Billman_ford货币升值——正权回路
2024-08-24 15:30:40
都是问货币能不能增多,钻社会制度得空子啊哈哈
唯一不同得是你的起点是任意一个点,这个比较麻烦了,多了一层循环嘞
处理货币名可以用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;
}
最新文章
- 在Mac中像Windows一样查看Tomcat控制台信息
- 【BZOJ-1426】收集邮票 概率与期望DP
- java文件cmd运行出现中文乱码
- Python学习——基础篇
- 切换Oracle数据库实例
- apache.commoms.digester3 解析xml文件
- activiti监听器使用
- MongoDB 运维相关的命令
- JSP页面静态包含和动态包含的区别与联系
- git连接不上远程仓库---visualstudio提交代码报错:no upstream configured for branch &#39;master&#39;
- kali自定义分辨率(1920*1080)
- HDU3613 Manacher//EXKMP//KMP
- Pytorch 入门之Siamese网络
- GoWeb-Gin 文件上载
- 学习模型-视图-控制器MVC模式
- 4-12 如何搜索API
- 字节(byte)与位(bit)基础回顾
- PCIe调试心得_DMA part3
- 基于终端的日志工具logview
- 搭建Apache服务器并使用自签证书实现https访问