Luogu P2419 [USACO08JAN]牛大赛Cow Contes
来源:互联网 发布:双色球缩水软件免费版 编辑:程序博客网 时间:2024/06/08 06:23
题目背景
[Usaco2008 Jan]
题目描述
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.
FJ的N(1 <= N <= 100)头奶牛们最近参加了场程序设计竞赛:)。在赛场上,奶牛们按1..N依次编号。每头奶牛的编程能力不尽相同,并且没有哪两头奶牛的水平不相上下,也就是说,奶牛们的编程能力有明确的排名。 整个比赛被分成了若干轮,每一轮是两头指定编号的奶牛的对决。如果编号为A的奶牛的编程能力强于编号为B的奶牛(1 <= A <= N; 1 <= B <= N; A != B) ,那么她们的对决中,编号为A的奶牛总是能胜出。 FJ想知道奶牛们编程能力的具体排名,于是他找来了奶牛们所有 M(1 <= M <= 4,500)轮比赛的结果,希望你能根据这些信息,推断出尽可能多的奶牛的编程能力排名。比赛结果保证不会自相矛盾。
输入输出格式
输入格式:
第1行: 2个用空格隔开的整数:N 和 M
第2..M+1行: 每行为2个用空格隔开的整数A、B,描述了参加某一轮比赛的奶 牛的编号,以及结果(编号为A,即为每行的第一个数的奶牛为 胜者)
输出格式:
第1行: 输出1个整数,表示排名可以确定的奶牛的数目
输入输出样例
5 54 34 23 21 22 5
2
说明
输出说明:
编号为2的奶牛输给了编号为1、3、4的奶牛,也就是说她的水平比这3头奶
牛都差。而编号为5的奶牛又输在了她的手下,也就是说,她的水平比编号为5的
奶牛强一些。于是,编号为2的奶牛的排名必然为第4,编号为5的奶牛的水平必
然最差。其他3头奶牛的排名仍无法确定。
1 #include<bits/stdc++.h> 2 using namespace std; 3 int read() 4 { 5 int ret=0,ok=1; 6 char ch=getchar(); 7 while(ch<'0'||ch>'9') 8 { 9 if(ch=='-')ok=-1;10 ch=getchar();11 }12 for(;ch>='0'&&ch<='9';ch=getchar())13 ret=ret*10+ch-'0';14 return ret*ok;15 }16 int n;17 int m;18 int a,b;19 int ans[150];20 int sp[150][150];21 int rans=0;22 int main()23 {24 n=read(),m=read();25 memset(sp,999999,sizeof(sp));26 for(int i=1;i<=m;i++)27 {28 a=read(),b=read();29 sp[a][b]=1;30 }31 for(int k=1;k<=n;k++)32 for(int i=1;i<=n;i++)33 for(int j=1;j<=n;j++)34 {35 if(i!=k&&i!=j&&k!=j&&sp[i][j]>sp[i][k]+sp[k][j])36 sp[i][j]=sp[i][k]+sp[k][j];37 }38 for(int i=1;i<=n;i++)39 for(int j=1;j<=n;j++)40 {41 if(sp[i][j]<0x7f)42 {43 ans[i]++;44 ans[j]++;45 }46 }47 for(int i=1;i<=n;i++)48 {49 if(ans[i]==n-1)50 rans++;51 }52 cout<<rans<<endl;53 return 0;54 }
- Luogu P2419 [USACO08JAN]牛大赛Cow Contes
- 洛谷p2419[USACO08JAN]牛大赛Cow Contest
- [USACO08JAN]牛大赛Cow Contest
- [luogu 2419]牛大赛Cow Contest
- [Usaco08Jan] Cow Contest
- luogu P1948 [USACO08JAN]电话线Telephone Lines
- Luogu P3120 [USACO15FEB]牛跳房子(金)Cow Hopscotch (Gold)
- Luogu P1969 [NOIP2013]积木大赛
- 【luogu 2863】[USACO06JAN]牛的舞会The Cow Prom题目描述
- Luogu P1969 [NOIp提高组2013]积木大赛
- luogu P1969积木大赛(NOIP 2013 TG)
- [USACO08JAN]电话线
- [Usaco08Jan&luogu1948] Telephone Lines
- 【USACO08JAN】洛谷1948 Telephone Lines
- cow
- COW
- cow
- 大赛
- 出现 java.net.MalformedURLException: no protocol 异常的原因及解决方法
- c语言基础
- 1758: [Wc2010]重建计划
- Rxjava 跳坑日记1
- oracle Advisor调优工具使用(命令行)
- Luogu P2419 [USACO08JAN]牛大赛Cow Contes
- 自用返回Json实体类JsonResult<T>
- NYOJ【75】日期计算【某年某月某日是第几天】
- 手机传感器数据处理
- android5.0无法使用HttpClient解决办法
- Java 统计各字符串元素出现的次数+map的遍历方式
- PHP date(); 日期和时间格式大全 PHP date("Y-m-d H:i:s"); 获取当前时间 差8小时解决办法
- SSL P2700 老妹的难题
- Recovery启动流程 --- 应用层到开机进入recovery详解