跟随kai巨巨,开始了寒假的刷题计划,简直刷新了我对刷题的看法!

每个专题,题目很多,我只能以自己的水平,把能写出来的 记一记、、、

B  Wormholes  POJ 3259

Description

While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that is BEFORE you entered the wormhole! Each of FJ's farms comprises N (1 ≤ N ≤ 500) fields conveniently numbered 1..N,M (1 ≤ M ≤ 2500) paths, and W (1 ≤ W ≤ 200) wormholes.

As FJ is an avid time-traveling fan, he wants to do the following: start at some field, travel through some paths and wormholes, and return to the starting field a time before his initial departure. Perhaps he will be able to meet himself :) .

To help FJ find out whether this is possible or not, he will supply you with complete maps toF (1 ≤ F ≤ 5) of his farms. No paths will take longer than 10,000 seconds to travel and no wormhole can bring FJ back in time by more than 10,000 seconds.

Input

Line 1: A single integer, F. F farm descriptions follow.
Line 1 of each farm: Three space-separated integers respectively: N, M, and W
Lines 2.. M+1 of each farm: Three space-separated numbers ( S, E, T) that describe, respectively: a bidirectional path between S and E that requires T seconds to traverse. Two fields might be connected by more than one path.
Lines M+2.. M+ W+1 of each farm: Three space-separated numbers (S, E, T) that describe, respectively: A one way path fromS to E that also moves the traveler back T seconds.

Output

Lines 1.. F: For each farm, output "YES" if FJ can achieve his goal, otherwise output "NO" (do not include the quotes).

Sample Input

2
3 3 1
1 2 2
1 3 4
2 3 1
3 1 3
3 2 1
1 2 3
2 3 4
3 1 8

Sample Output

NO
YES

Hint

For farm 1, FJ cannot travel back in time.
For farm 2, FJ could travel back in time by the cycle 1->2->3->1, arriving back at his starting location 1 second before he leaves. He could start from anywhere on the cycle to accomplish this.

题意:输入一个数F,接下来有F组数据, 输入三个数n, m, w。n 代表点的个数,m 代表双向路径的对数,且权值为正,w 代表单向路径的对数,权值为负。最后要求的就是,判断是否存在负环,存在则输出YES, 不存在就输出NO

可以用bellman - ford 来做,用的kuangbin 的模版 ,模版有错- -# 搞了半天、、

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <vector>
using namespace std;const int INF = 0x3f3f3f3f;
const int MAXN = 5500;
int dist[MAXN];
int n, m;struct Edge
{int u, v;int cost;Edge(int _u = 0, int _v = 0, int _cost = 0): u(_u), v(_v), cost(_cost){}
};vector<Edge> E;bool bellman_ford(int start)
{for(int i = 1; i <= n; i ++)dist[i] = INF;dist[start] = 0;for(int i = 1; i < n; i ++){bool flag = false;for(int j = 0; j < E.size(); j ++){int u = E[j].u;int v = E[j].v;int cost = E[j].cost;if(dist[v] > dist[u] + cost){dist[v] = dist[u] + cost;flag = true;}}if(!flag)break;}for(int j = 0; j < E.size(); j ++){if(dist[E[j].v] > dist[E[j].u] + E[j].cost)return true;}return false;
}int main()
{int T;int w, s, e, t;while(~scanf("%d",&T)){while(T --){while(!E.empty()){E.pop_back();}scanf("%d%d%d",&n,&m,&w);for(int i = 1; i <= m ;i ++){scanf("%d%d%d",&s, &e, &t);E.push_back((Edge){s, e, t});E.push_back((Edge){e, s, t});}for(int j = 1; j <= w; j ++){scanf("%d%d%d",&s,&e,&t);E.push_back((Edge){s, e, -t});}/* for(int i = 0; i < E.size(); i ++){printf("%d %d %d\n", E[i].u, E[i].v, E[i].cost);}*/if(bellman_ford(1)){printf("YES\n");}elseprintf("NO\n");}}
}

F  POJ 2240

Description

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 British pound, 1 British pound buys 10.0 French francs, and 1 French franc buys 0.21 US dollar. Then, by converting currencies, a clever trader can start with 1 US dollar and buy 0.5 * 10.0 * 0.21 = 1.05 US dollars, making a profit of 5 percent.

Your job is to write a program that takes a list of currency exchange rates as input and then determines whether arbitrage is possible or not.

Input

The input will contain one or more test cases. Om the first line of each test case there is an integer n (1<=n<=30), representing the number of different currencies. The next n lines each contain the name of one currency. Within a name no spaces will appear. The next line contains one integer m, representing the length of the table to follow. The last m lines each contain the name ci of a source currency, a real number rij which represents the exchange rate from ci to cj and a name cj of the destination currency. Exchanges which do not appear in the table are impossible.
Test cases are separated from each other by a blank line. Input is terminated by a value of zero (0) for n.

Output

For each test case, print one line telling whether arbitrage is possible or not in the format "Case case: Yes" respectively "Case case: No".

Sample Input

3
USDollar
BritishPound
FrenchFranc
3
USDollar 0.5 BritishPound
BritishPound 10.0 FrenchFranc
FrenchFranc 0.21 USDollar3
USDollar
BritishPound
FrenchFranc
6
USDollar 0.5 BritishPound
USDollar 4.9 FrenchFranc
BritishPound 10.0 FrenchFranc
BritishPound 1.99 USDollar
FrenchFranc 0.09 BritishPound
FrenchFranc 0.19 USDollar0

Sample Output

Case 1: Yes
Case 2: No

floyd 的 一个变种

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <string.h>
using namespace std;#define N 110map <string, int> mp;
double tt[N][N];
int n, m;bool floyd()
{for( int k = 1; k <= n; k ++)for( int i = 1; i <= n; i ++)for( int j = 1; j <= n; j ++)if( tt[i][j] < tt[i][k] * tt[k][j])tt[i][j] = tt[i][k] * tt[k][j];for( int i = 1; i <= n; i ++)if( tt[i][i] > 1)return true;return false;
}int main()
{double a;char t[110];char t1[110];char t2[110];int icase = 1;while(~scanf("%d",&n),n){memset(tt, 0, sizeof(tt));for(int i = 1; i <= n; i ++){scanf("%s",t);mp[t] = i;}scanf("%d",&m);for(int i = 1; i <= m; i ++){scanf("%s%lf%s", t1, &a, t2);tt[ mp[t1] ][ mp[t2] ] = a;}printf("Case %d: ", icase ++);if(floyd())printf("Yes\n");elseprintf("No\n");}
}

E  POJ 1125

Description

Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst the stockbrokers to give your employer the tactical edge in the stock market. For maximum effect, you have to spread the rumours in the fastest possible way.

Unfortunately for you, stockbrokers only trust information coming from their "Trusted sources" This means you have to take into account the structure of their contacts when starting a rumour. It takes a certain amount of time for a specific stockbroker to pass the rumour on to each of his colleagues. Your task will be to write a program that tells you which stockbroker to choose as your starting point for the rumour, as well as the time it will take for the rumour to spread throughout the stockbroker community. This duration is measured as the time needed for the last person to receive the information.

Input

Your program will input data for different sets of stockbrokers. Each set starts with a line with the number of stockbrokers. Following this is a line for each stockbroker which contains the number of people who they have contact with, who these people are, and the time taken for them to pass the message to each person. The format of each stockbroker line is as follows: The line starts with the number of contacts (n), followed by n pairs of integers, one pair for each contact. Each pair lists first a number referring to the contact (e.g. a '1' means person number one in the set), followed by the time in minutes taken to pass a message to that person. There are no special punctuation symbols or spacing rules.

Each person is numbered 1 through to the number of stockbrokers. The time taken to pass the message on will be between 1 and 10 minutes (inclusive), and the number of contacts will range between 0 and one less than the number of stockbrokers. The number of stockbrokers will range from 1 to 100. The input is terminated by a set of stockbrokers containing 0 (zero) people.

Output

For each set of data, your program must output a single line containing the person who results in the fastest message transmission, and how long before the last person will receive any given message after you give it to this person, measured in integer minutes.
It is possible that your program will receive a network of connections that excludes some persons, i.e. some people may be unreachable. If your program detects such a broken network, simply output the message "disjoint". Note that the time taken to pass the message from person A to person B is not necessarily the same as the time taken to pass it from B to A, if such transmission is possible at all.

Sample Input

3
2 2 4 3 5
2 1 2 3 6
2 1 2 2 2
5
3 4 4 2 8 5 3
1 5 8
4 1 6 4 10 2 7 5 2
0
2 2 5 1 5
0

Sample Output

3 2
3 10

感觉怪怪的,有点问题、、

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;const int INF = 0xffffff;int map[150][150];
int dis[150];
int vis[150];
int n;int dij(int sour)
{int i, j, k;int t;for(i = 1; i <= n; i ++){vis[i] = 0;dis[i] = map[sour][i];}vis[sour] = 1;int min;for(i = 1; i < n; i ++){min = INF;t = 0;for(j = 1; j <= n; j ++){if(!vis[j] && min > dis[j]){t = j;min = dis[j];}}vis[t] = 1;for(j = 1; j <= n; j ++){int newdis = min + map[t][j];if(!vis[j] && dis[j] > newdis){dis[j] = newdis;}}}/*for(int i = 1; i <= n; i ++){if(vis[i] == 0)return -1;}*/return min;
}void init()
{for(int i = 0 ; i <= n; i ++){for(int j = 0; j <= n; j ++){map[i][j] = INF;}}
}int main()
{int a, b;while(~scanf("%d",&n), n){init();for(int j = 1; j <= n; j ++){scanf("%d",&a);for(int i = 1; i <= a; i ++){scanf("%d",&b);scanf("%d",&map[j][b]);}}bool flag = false;int minn = dij(1);int ans = 1;for(int i = 2; i <= n; i ++){int tmp_1 = dij(i);if(tmp_1 == -1){printf("disjoint\n");break;flag = true;}if(tmp_1 < minn){minn = tmp_1;ans = i;}}if(flag)continue;printf("%d %d\n",ans, minn);}return 0;
}

【 题集 】 寒假计划——最短路相关推荐

  1. ACM题集以及各种总结大全(转)

    ACM题集以及各种总结大全! 虽然退役了,但是整理一下,供小弟小妹们以后切题方便一些,但由于近来考试太多,顾退役总结延迟一段时间再写!先写一下各种分类和题集,欢迎各位大牛路过指正. 一.ACM入门 关 ...

  2. 【训练计划】ACM题集以及各种总结大全

    ACM题集以及各种总结大全! 虽然退役了,但是整理一下,供小弟小妹们以后切题方便一些,但由于近来考试太多,顾退役总结延迟一段时间再写!先写一下各种分类和题集,欢迎各位大牛路过指正. 一.ACM入门 关 ...

  3. ACM题集以及各种总结大全

    ACM题集以及各种总结大全! 虽然退役了,但是整理一下,供小弟小妹们以后切题方便一些,但由于近来考试太多,顾退役总结延迟一段时间再写!先写一下各种分类和题集,欢迎各位大牛路过指正. 一.ACM入门 关 ...

  4. 一本好的“错题集”如何做?看这里

    <错题本>制作 每个人肯定都有听说,错题本对高考到底多么多么有用,对我们的复习多么多么有用.但是问题也来了,做错题本好像要用我们很多的时间,可能做完了还空看,那怎么办呢?今天本车从做错题本 ...

  5. 阿里云ACP云计算错题集41-70

    每天学一点阿里云ACP认证,这里是ACP错题集.by Moshow郑锴(大狼狗) zhengkai.blog.csdn.net 41.在使用阿里云弹性伸缩(Auto Scaling)时,伸缩组中包含的 ...

  6. 阿里云ACP云计算错题集121-140

    每天学一点阿里云ACP认证,这里是ACP错题集.温故而知新,从错题入手,可以更好理解出题点.难点. by zhengkai.blog.csdn.net 121.当您发现无法将指定的阿里云的块存储挂载到 ...

  7. 2019年寒假计划(1月17日——2月22日)

    期末考试周结束,寒假来临. 新的一年中上半年我需要准备蓝桥杯以及acm,下半年迎接考研. 这个寒假对我而言就变得十分重要,为了好好利用这个寒假特此制定寒假计划 一.需每天坚持的计划 1.数据结构与算法 ...

  8. 总结及寒假计划 2019.1

    总结: 2019的第一个月已经接近尾声了,在这里总结一下自己的大二上学期. 说句实话,感觉自己这一学期过的很垃圾,注意力被过多的东西所分散,但是这一学期我也深刻的认识到了什么叫兴趣是最好的老师.今年接 ...

  9. PMP备考-错题集(第6版)

    这是我自己备考过程中,记录的错题集. 1. [单选] 作为你们公司项目办公室的经理,你必须经常判定哪些项目应该得到额外的资源.你还要建议哪些项目应该启动.继续进行或取消.有利于你做出这些决策的一个方法 ...

最新文章

  1. 获取注解中的属性信息
  2. python交作业的格式_python作业4
  3. OpenCV自定义CN跟踪器
  4. JSP中获取HTML中的中文内容是乱码的解决方法---开发中遇到的问题
  5. 第五节: EF高级属性(一) 之 本地缓存、立即加载、延迟加载(不含导航属性)
  6. 在python中、对于函数定义代码的理解_python中如何理解装饰器代码?
  7. 计算机控制系统EHA,优·计算机控制技术第四章.doc
  8. xampp 运行 yaf框架
  9. js事件的冒泡(bubble)机制说明
  10. 给大家推荐一个经典的ping工具-MTR
  11. 算法笔记(胡凡)刷题笔记目录
  12. MySQL安装配置教程(超级详细、保姆级)
  13. 智能电动自行车充电桩系统解决方案
  14. 认识BLE 5协议栈 —— 直接测试模式
  15. 微信单删和互删有什么区别?
  16. wwbizsrv.exe-应用程序错误
  17. Android-Socket传输 GPRS网络
  18. 一个小白的转行自学Python的经历
  19. matlab 人人,matlab pivlab
  20. 用打印指令设置Zebra Printer的IP地址(适用于GK888T带打印服务器的条码打印机)

热门文章

  1. 学java用什么软件_学java需要用到什么软件?用哪个软件比较好?
  2. 音速索尼克 怪人_最奇妙的刺猬索尼克粉丝游戏
  3. 2020双十一活动怎么玩?做好这3点引爆销量!
  4. 打造无懈可击的Web设计——流动布局和弹性布局
  5. 37岁985老兵,小公司朝九晚五,大龄底层没机会了!
  6. 用python画股票价格走势图
  7. 安全测试中sql注入测试思路
  8. 已知一个如图所示的训练数据集,其正例点是x1=(3,3),x1=(4,3),负例点是x3=(1,1),试求最大间隔分离超平面。
  9. 阅文java面试_面试官:说说Redis的Hash底层 我:......(来自阅文的面试题)
  10. linux报错:/bin/sh: 1: flex: not found scripts/Makefile.host:9: recipe for target ‘scripts/kconfig/lexe