22401860那个题目很像啊

都是问货币能不能增多,钻社会制度得空子啊哈哈

唯一不同得是你的起点是任意一个点,这个比较麻烦了,多了一层循环嘞

处理货币名可以用map分配id

然后就是老套的Billman_ford算法了

#include <iostream>
#include <map>
#include <vector>
#include <string.h>
#include <cstdio>
#include <string>
using namespace std;
const int maxn = 40;
map<string,int> id;
double dis[maxn];
struct node{
int from,to;
double v;
node(int f,int t,double va):from(f),to(t),v(va){}
node(){}
};

这次联系了Stl中得容器,熟悉熟悉

int main()
{
int n,m;
string s,a,b;
double v;
int cas = 1;
while(~scanf("%d",&n),n)
{
id.clear();
edge.clear();
for(int i = 1;i <= n;i++)
{
cin>>s;
id[s] = i;
}
scanf("%d",&m);
while(m--)
{
cin>>a;
scanf("%lf",&v);
cin>>b;
edge.push_back(node(id[a],id[b],v));
}
printf("Case %d: ",cas++);
for(int i = 1;i <= n;i++)
{
if(blm(i,n))
{
printf("Yes\n");
break;
}
else if(i == n)printf("No\n");
}
}
return 0;
}
vector<node> edge;
bool blm(int s,int n)
{
for(int i = 1;i <= n;i++)dis[i] = 0;
dis[s] = 1.0;
for(int i = 1;i < n;i++)
{
for(int j = 0;j < edge.size();j++)
{
int from = edge[j].from;
int to = edge[j].to;
double v = edge[j].v;
//cout<<from<<" "<<to<<" "<<v<<endl;
dis[to] = max(dis[to],dis[from] * v);
}
//cout<<"cs"<<endl;
}
for(int i = 0;i < edge.size();i++)
{
int from = edge[i].from;
int to = edge[i].to;
double v = edge[i].v;
if(dis[to] < dis[from] * v)return true;
}
return false;
}

最新文章

  1. 在Mac中像Windows一样查看Tomcat控制台信息
  2. 【BZOJ-1426】收集邮票 概率与期望DP
  3. java文件cmd运行出现中文乱码
  4. Python学习——基础篇
  5. 切换Oracle数据库实例
  6. apache.commoms.digester3 解析xml文件
  7. activiti监听器使用
  8. MongoDB 运维相关的命令
  9. JSP页面静态包含和动态包含的区别与联系
  10. git连接不上远程仓库---visualstudio提交代码报错:no upstream configured for branch &#39;master&#39;
  11. kali自定义分辨率(1920*1080)
  12. HDU3613 Manacher//EXKMP//KMP
  13. Pytorch 入门之Siamese网络
  14. GoWeb-Gin 文件上载
  15. 学习模型-视图-控制器MVC模式
  16. 4-12 如何搜索API
  17. 字节(byte)与位(bit)基础回顾
  18. PCIe调试心得_DMA part3
  19. 基于终端的日志工具logview
  20. 搭建Apache服务器并使用自签证书实现https访问

热门文章

  1. nfs只能挂载为nobody的解决方法
  2. 给vim编辑器自动添加行号
  3. RecycleView实现侧滑删除item
  4. Date.parse和new Date(str)的兼容性问题
  5. 第八章&#160;高级搜索树 (a1)伸展树:逐层伸展
  6. cdoj842-天下归晋 【树状数组】
  7. Poor Warehouse Keeper
  8. queue,stack的相互实现
  9. python数据类型内部结构解剖
  10. 对于某些浏览器不支持placeholder的解决办法