【POJ 1860】Currency Exchange
【题目链接】:http://poj.org/problem?id=1860
【题意】
给你n种货币,m种货币之间的交换信息;
交换信息以
A,B,RA,CA,RB,CB的形式给出;
即A换B的话假设A有x元则换成B就变成(X-CA)*RA
B换成A的话同理;
然后你一开始只有某一种x货币;
问你可不可能通过换货币来获得更多x货币;
即最后又要换回来.
【题解】
可以在做SPFA的最长路的时候判断能不能出现环.
具体的。
只要从x出去了,然后又回来了;
就说明能够在经过某些路径之后这个x又变大了;
任意哪一个x都可以;
因为你可以通过这条路径让x变得无穷大;
那么起点s肯定也能无穷大啦;
判断环的话只要判断一个点是否入队n次就好;
【Number Of WA】
1
【完整代码】
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
const int N = 110;
const int INF = 0x3f3f3f3f;
struct abc
{
int en;
double r,c;
};
int n,m,s,num[N];
bool inq[N];
double dis[N];
vector <abc> G[N];
queue <int> dl;
int main()
{
//freopen("F:\\rush.txt","r",stdin);
memset(dis,-INF,sizeof dis);
cin >> n >> m >> s;cin >> dis[s];
for (int i = 1;i <= m;i++)
{
int x,y;
double r,c;
abc temp;
cin >>x >> y >> r >> c;
temp.r = r,temp.c = c,temp.en = y;
G[x].push_back(temp);
cin >> r >> c;
temp.r = r,temp.c = c,temp.en = x;
G[y].push_back(temp);
}
dl.push(s);
num[s]=1;
inq[s] = true;
while (!dl.empty())
{
int x = dl.front();
inq[x] = false;
dl.pop();
int len = G[x].size();
for (int i = 0;i <= len-1;i++)
{
abc temp1 = G[x][i];
int y = temp1.en;
double ju = (dis[x]-temp1.c)*temp1.r;
if (ju>0)
{
if (dis[y]<ju)
{
dis[y] = ju;
if (!inq[y])
{
num[y]++;
if (num[y]>n)
return cout <<"YES"<<endl,0;
dl.push(y);
inq[y]=true;
}
}
}
}
}
cout <<"NO"<<endl;
return 0;
}
【POJ 1860】Currency Exchange的更多相关文章
- POJ 1860:Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22648 Accepted: 818 ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
随机推荐
- sqlserver 触发器实例代码
定义: 何为触发器?在SQL Server里面也就是对某一个表的一定的操作,触发某种条件,从而执行的一段程序.触发器是一个特殊的存储过程. 常见的触发器有三种:分别应用于Insert , Update ...
- Datatable转换为Json 的方法
/// <summary> /// Datatable转换为Json /// </summary> /// <param n ...
- 【XSY3209】RGB Sequence
题目 传送门 解法 用\(f_{i, j, k}\)表示有\(i\)个红石块, \(j\)个绿宝石块, \(k\)个钻石块 可以转移到\(f_{p+1, j, k}\). \(f_{i, p+1,k ...
- [Swift通天遁地]四、网络和线程-(12)使用ReachabilitySwift实现对网络状态的检测
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- iview日期选择框,获取的日期总是少一天
使用iview的datepicker时间选择器发现获取的value值是比实际要少一天,严格来说应该是时间格式不一样,datepicker获取的时间是UTC时间 格式,也就是:yyyy-MM-ddTHH ...
- hdu---3177 Crixalis's Equipment 根据 两个元素 之间的权衡进行排序
Crixalis's Equipment Problem Description Crixalis - Sand King used to be a giant scorpion(蝎子) in the ...
- Educational Codeforces Round 24 题解
A: 考你会不会除法 //By SiriusRen #include <bits/stdc++.h> using namespace std; #define int long long ...
- ACM_Jack拆炸弹(深搜)
Jack拆炸弹 Time Limit: 2000/1000ms (Java/Others) Problem Description: 在一个由n*n个格子组成的监狱里被恐怖份子安置了一个定时炸弹.其中 ...
- Quartz在服务异常中断或者重启后,不执行之前漏掉的任务,重新运行下一次任务
Quartz默认重启后会执行之前的任务,所以如果不想执行之前漏掉的任务,需要设置一下两个地方: CRON triggers CronTrigger trigger = TriggerBuilder.n ...
- 【百度之星】-IP聚合
问题描述: Problem Description 当今世界,网络已经无处不在了,小度熊由于犯了错误,当上了度度公司的网络管理员,他手上有大量的 IP列表,小度熊想知道在某个固定的子网掩码下,有多少个 ...