poj-3660-cows contest(不懂待定)
2016-03-22 17:16
351 查看
Description
N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among the competitors.
The contest is conducted in several head-to-head rounds, each between two cows. If cow A has a greater skill level than cow B (1 ≤ A ≤ N; 1 ≤ B ≤ N; A ≠ B), then cow A will always beat cow B.
Farmer John is trying to rank the cows by skill level. Given a list the results of M (1 ≤ M ≤ 4,500) two-cow rounds, determine the number of cows whose ranks can be precisely determined from the results. It is guaranteed that the results of the rounds will not be contradictory.
Input
* Line 1: Two space-separated integers: N and M
* Lines 2..M+1: Each line contains two space-separated integers that describe the competitors and results (the first integer, A, is the winner) of a single round of competition: A and B
Output
* Line 1: A single integer representing the number of cows whose ranks can be determined
Sample Input
N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among the competitors.
The contest is conducted in several head-to-head rounds, each between two cows. If cow A has a greater skill level than cow B (1 ≤ A ≤ N; 1 ≤ B ≤ N; A ≠ B), then cow A will always beat cow B.
Farmer John is trying to rank the cows by skill level. Given a list the results of M (1 ≤ M ≤ 4,500) two-cow rounds, determine the number of cows whose ranks can be precisely determined from the results. It is guaranteed that the results of the rounds will not be contradictory.
Input
* Line 1: Two space-separated integers: N and M
* Lines 2..M+1: Each line contains two space-separated integers that describe the competitors and results (the first integer, A, is the winner) of a single round of competition: A and B
Output
* Line 1: A single integer representing the number of cows whose ranks can be determined
Sample Input
5 5 4 3 4 2 3 2 1 2 2 5 分析:有人说叫闭包传递。这题就是用一种类似于floyd的算法, 开始时,如果a胜b则由a到b连一条边。这样所有a能走到的点都是排名在a以后的。 所有能走到a的点都是排名在a以前的。用floyd,求出每个点能到达的点。 如果有一个点,排名在它之前的和排名在它之后的点之和为n-1,那么它的排名就是确定的。
#include<iostream> using namespace std ; int main() { int N,M,a,b; cin>>N>>M; int aa[110][110]={0}; while(M--) { cin>>a>>b; aa[a][b]=1; } for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) for(int k=1;k<=N;k++) { if(aa[j][i]&&aa[i][k]) aa[j][k]=1; } int ans=0; for(int i=1;i<=N;i++) { int tmp=0; for(int j=1;j<=N;j++) tmp+=aa[i][j]+aa[j][i]; if(tmp==N-1)ans++; } cout<<ans<<endl; return 0; }
相关文章推荐
- docker 私有仓库镜像的存储位置
- docker 私有仓库镜像的存储位置
- TextView内容太长怎么办?
- 触发Full GC执行的情况 JVM对象分配规则
- hdoj1013
- AudioQueueStart Fail问题
- python读取xlsx文件
- [PHP代码] PHP四舍五入 保留几位小数 格式化数字
- android关于canvas,path,paint非常好的讲解
- BZOJ 1194: [HNOI2006]潘多拉的盒子
- Lua的文件操作自定义上传头像
- 给工程师的 10 条哲理(浅薄者迷信运气,强者相信因果,软件复制成本为零,文凭不重要,AWS使得创业成本为零,每个手机都是口袋里的强大电脑)
- Gulp自动添加版本号
- 数字签名与数字证书
- [PHP代码] php模拟post发送数据
- 安卓触摸事件探究
- Jena读取Ontology本体到Mysql数据库
- 【字符串处理算法】获取最长公共子串的算法设计及C代码实现
- matlab下创建带变量的文件夹
- 数据结构学习路线+笔记