跟poj1860类似 判断是否存在正环,bellman-ford每个点做一次正环判断,刚开始以为每种货币都要能升值,错了,后来又因为case后面少打了个空格 晕
code
#include <set>
#include <map>
#include <ctime>
#include <queue>
#include <cmath>
#include <stack>
#include <limits>
#include <vector>
#include <bitset>
#include <string>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <string.h>
#include <iostream>
#include <algorithm>
#define Si set<int>
#define LL long long
#define pb push_back
#define PS printf(" ")
#define Vi vector<int>
#define LN printf("\n")
#define lson l,m,rt << 1
#define rson m+1,r,rt<<1|1
#define SD(a) scanf("%d",&a)
#define PD(a) printf("%d",a)
#define SET(a,b) memset(a,b,sizeof(a))
#define FF(i,a) for(int i(0);i<(a);i++)
#define FD(i,a) for(int i(a);i>=(1);i--)
#define FOR(i,a,b) for(int i(a);i<=(b);i++)
#define FOD(i,a,b) for(int i(a);i>=(b);i--)
#define readf freopen("input.txt","r",stdin)
#define writef freopen("output.txt","w",stdout)
const int maxn = 201;
const long long BigP=999983;
const int INF = 0x3fffffff;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
const double pi = acos(-1.0);
const double eps= 1e-7;
using namespace std;
int N,M,e_cnt;
char name[31][50];
double dis[maxn];
struct edge{
int from,to;
double w;
}E[501];
void add_E(int from,int to,double w){
E[++e_cnt].to=to;
E[e_cnt].w=w;
E[e_cnt].from=from;
}
bool bellman_ford(int s){
SET(dis,0);
dis[s]=1;
bool flag;
while(dis[s]<=1+eps){
flag=false;
FOR(i,0,e_cnt){
if(dis[E[i].to]<dis[E[i].from]*E[i].w){
dis[E[i].to]=dis[E[i].from]*E[i].w;
flag=true;
}
}
if(!flag){
if(dis[s]>1+eps) return true;
else return false;
}
}
return true;
}
int main(){
int cnt=1;
while(~SD(N) &&N){
e_cnt=0;
FOR(i,1,N){
scanf("%s",name[i]);
}
char ch[50];int k1,k2;double t;
SD(M);
FOR(i,1,M){
scanf("%s",ch);
FOR(j,1,N){
if(!strcmp(ch,name[j])){
k1=j;
}
}
scanf("%lf",&t);
scanf("%s",ch);
FOR(j,1,N){
if(!strcmp(ch,name[j])){
k2=j;
}
}
add_E(k1,k2,t);
}
printf("Case %d: ",cnt++);
bool flag=false;
FOR(i,1,N){
if(bellman_ford(i)){
flag=true;
break;
}
}
if(flag) puts("Yes");
else puts("No");
}
return 0;
}
分享到:
相关推荐
北大POJ2240-Arbitrage【Floyd】 解题报告+AC代码
Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US Dollar buys 0.5 ...
POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类
poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题...
POJ第1861题源码 POJ第1861题源码 POJ第1861题源码
北大POJ1159-Palindrome 解题报告+AC代码
C语言 poj npu 西工大 C语言Poj答案全完整打包,给有需要的朋友
poj 3414解题报告poj 3414解题报告poj 3414解题报告poj 3414解题报告
poj分类poj分类poj分类poj分类
poj 1012解题报告poj 1012解题报告poj 1012解题报告poj 1012解题报告
北大POJ2002-Squares 解题报告+AC代码
poj 2329解题报告poj 2329解题报告poj 2329解题报告poj 2329解题报告
POJ1503解答 POJ1503解答,正确答案(已通过POJ)
POJ1048,加强版的约瑟夫问题 难度中等
poj 1659解题报告poj 1659解题报告poj 1659解题报告poj 1659解题报告
POJ1083的代码,POJ1083的代码,POJ1083的代码
poj 百练 题目分类 poj 百练 题目分类
POJ上的一道题目,自己写的代码,因为想下载别人的, 所以就放上了。
POJ2968代码有用,欢迎下载,POJ代码
Poj中一些题目的源代码,里面共有二十多道题目,OI