kuangbin_ShortPath I (POJ 2240)
本身很简单的spfa判环 TLE了一把是因为没写map(不会)
看着别人的答案临时学了一发发现只是用的话还是挺简单的 (但是绝对别学别人直接命名为m) 800多MS水过
噢对了这题Pending到超时了三次 POI绝对有毒
#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
using namespace std; map<string, int> mapp;
double val[][];
int n, m; bool spfa(int s)
{
double dis[];
bool vis[];
int time[];
memset(dis, , sizeof dis);
memset(vis, , sizeof vis);
memset(time, , sizeof time); queue<int> q;
dis[s] = 1.0;
vis[s] = true;
q.push(s);
while(!q.empty()){
int u = q.front();
q.pop();
vis[u] = false;
for(int i = ; i <= n; i++){
if(dis[i] < dis[u] * val[u][i]){
dis[i] = dis[u] * val[u][i];
if(!vis[i]){
vis[i] = true;
q.push(i);
if(++time[i] >= n) return true;
}
}
}
}
return false;
}
int main()
{
int kase = ;
while(){
cin >> n;
if(n == ) break;
memset(val, , sizeof val);
for(int i = ; i <= n; i++){
string str;
cin >> str;
mapp[str] = i;
}
cin >> m;
for(int i = ; i <= m; i++){
string str1, str2;
double value;
cin >> str1 >> value >> str2;
val[mapp[str1]][mapp[str2]] = value;
}
if(spfa()) cout << "Case " << ++kase << ": Yes" << endl;
else cout << "Case " << ++kase << ": No" << endl;
}
return ;
}
kuangbin_ShortPath I (POJ 2240)的更多相关文章
- 最短路(Floyd_Warshall) POJ 2240 Arbitrage
题目传送门 /* 最短路:Floyd模板题 只要把+改为*就ok了,热闹后判断d[i][i]是否大于1 文件输入的ONLINE_JUDGE少写了个_,WA了N遍:) */ #include <c ...
- poj 2240 Arbitrage (Floyd)
链接:poj 2240 题意:首先给出N中货币,然后给出了这N种货币之间的兑换的兑换率. 如 USDollar 0.5 BritishPound 表示 :1 USDollar兑换成0.5 Britis ...
- POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)
POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...
- poj 2240 Arbitrage 题解
Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21300 Accepted: 9079 Descri ...
- poj 2240(floyd)
http://poj.org/problem?id=2240 题意:有些人会利用货币的不用汇率来进行套现,比如1美元换0.5英镑,而1英镑又可以换10法郎,而1法郎又可以换0.21的美元,那么经过货币 ...
- POJ 2240 && ZOJ 1082 Arbitrage 最短路,c++ stl pass g++ tle 难度:0
http://poj.org/problem?id=2240 用log化乘法为加法找正圈 c++ 110ms,g++tle #include <string> #include <m ...
- POJ 2240 Arbitrage(floyd)
http://poj.org/problem?id=2240 题意 : 好吧,又是一个换钱的题:套利是利用货币汇率的差异进行的货币转换,例如用1美元购买0.5英镑,1英镑可以购买10法郎,一法郎可以购 ...
- poj 2240 Arbitrage (最短路 bellman_ford)
题目:http://poj.org/problem?id=2240 题意:给定n个货币名称,给m个货币之间的汇率,求会不会增加 和1860差不多,求有没有正环 刚开始没对,不知道为什么用 double ...
- POJ 2240 Arbitrage【Bellman_ford坑】
链接: http://poj.org/problem?id=2240 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
随机推荐
- xlistview的XML(脚)xlistview_footer
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" ...
- Embedded binary is not signed with the same certificate as the parent app
I face the same issue too,I solve it by this: First, I reCreate my team develop certificate(Because ...
- 2014年2月份第4周51Aspx源码发布详情
AM自定义报表管理系统源码 2014-2-28 [VS2010]源码描述: 本系统有以下特色之处: 1.一套软件,多点登陆,根据权限不同共同管理报表,适应于前期获取客户需求报表字段使用. 2.客户自 ...
- 《AppletButtonEvent.java》
//AppletButtonEvent.java import java.applet.*; import java.awt.*; import java.awt.event.*; public cl ...
- Java基础毕向东day02
1. 常量 null 等特殊 2.标识符 数字-字母-下划线,数字不能开头 3.二进制 1> 二进制计算方法. 2>常用二进制. 1 1 0 0 1 ...
- 利用pl/sql developer进行远程连接oracle server出现的问题及解决办法
由于本人刚刚给自己的笔记本做了系统,由原来的32位系统编程现在的64位系统,所以,很多软件由于兼容性,不得不重新安装...当我安完了pl/sql developer工具后,就满心欢喜的去连接远程ora ...
- openstack 中 log模块分析
1 . 所在模块,一般在openstack/common/log.py,其实最主要的还是调用了python中的logging模块: 入口函数在 def setup(product_name, vers ...
- detangle c++ symbols
hust$ c++filt _ZN1AC2Ev hust$A::A()
- 【LeetCode OJ】Best Time to Buy and Sell Stock III
Problem Link: http://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/ Linear Time Solut ...
- Fix a corrupted user profile
Fix a corrupted user profile Applies to Windows 7 Your user profile is a collection of settings that ...