当前位置:网站首页>POJ3275 Ranking the Cows题解
POJ3275 Ranking the Cows题解
2022-07-28 12:37:00 【bj_hacker】
题目
链接
http://poj.org/problem?id=3275
字面描述
Ranking the Cows
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 3893 Accepted: 1754
Description
Each of Farmer John’s N cows (1 ≤ N ≤ 1,000) produces milk at a different positive rate, and FJ would like to order his cows according to these rates from the fastest milk producer to the slowest.
FJ has already compared the milk output rate for M (1 ≤ M ≤ 10,000) pairs of cows. He wants to make a list of C additional pairs of cows such that, if he now compares those C pairs, he will definitely be able to deduce the correct ordering of all N cows. Please help him determine the minimum value of C for which such a list is possible.
Input
Line 1: Two space-separated integers: N and M
Lines 2…M+1: Two space-separated integers, respectively: X and Y. Both X and Y are in the range 1…N and describe a comparison where cow X was ranked higher than cow Y.
Output
Line 1: A single integer that is the minimum value of C.
Sample Input
5 5
2 1
1 5
2 3
1 4
3 4
Sample Output
3
Hint
From the information in the 5 test results, Farmer John knows that since cow 2 > cow 1 > cow 5 and cow 2 > cow 3 > cow 4, cow 2 has the highest rank. However, he needs to know whether cow 1 > cow 3 to determine the cow with the second highest rank. Also, he will need one more question to determine the ordering between cow 4 and cow 5. After that, he will need to know if cow 5 > cow 3 if cow 1 has higher rank than cow 3. He will have to ask three questions in order to be sure he has the rankings: “Is cow 1 > cow 3? Is cow 4 > cow 5? Is cow 5 > cow 3?”
Source
USACO 2007 March Gold
代码实现
#include<cstdio>
#include<bitset>
using namespace std;
const int maxn=1e3+10;
int n,m,ans;
bitset<maxn>mp[maxn];
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
mp[x][y]=1;
}
for(int j=1;j<=n;j++){
for(int i=1;i<=n;i++){
if(mp[i][j])mp[i]|=mp[j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(mp[i][j])ans++;
}
}
printf("%d\n",n*(n-1)/2-ans);
return 0;
}
边栏推荐
- 面经整理,助力秋招,祝你称为offer收割机
- Leetcode notes 566. Reshaping the matrix
- 倒计时 2 天!2022 中国算力大会:移动云邀您共见算力网络,创新发展
- Humiliation, resistance, reversal, 30 years, China should win Microsoft once
- [报错]使用ssh登陆到另一台机器后,发现主机名还是自己|无法访问yarn8088
- [C language] the difference between structure pointer and structure variable as formal parameters
- Operator3-设计一个operator
- C language: optimized merge sort
- What if the server cannot be connected (the original server cannot find the target resource)
- One track education, PHP training, unity of knowledge and practice, popular
猜你喜欢

少儿编程 电子学会图形化编程等级考试Scratch二级真题解析(判断题)2022年6月

Operator3-设计一个operator

Can second uncle cure young people's spiritual internal friction?

持续(集成--&gt;交付--&gt;部署)

Leetcode · daily question · 1331. array sequence number conversion · discretization

Leetcode-136. numbers that appear only once

Night God simulator packet capturing wechat applet

从手机厂高位“出走”的三个男人

国产API管理工具Eolink太好用了,打造高效的研发利器

夜神模拟器抓包微信小程序
随机推荐
Intra prediction and transform kernel selection based on Neural Network
火山石投资章苏阳:硬科技,下一个10年相对确定的答案
leetcode-136.只出现一次的数字
Rust from introduction to mastery 01 introduction
Gamestop bear market entered NFT trading, and established game retailers took advantage of Web3 to make a second spring
Fast classification of array.group() in ES6
leetcdoe-342. 4的幂
docker部署mysql 实现远程连接[通俗易懂]
Shell basic concepts and variables
用非递归的方法实现二叉树中的层遍历,先序遍历,中序遍历和后序遍历
Debezium系列之:2.0.0.Beta1的重大变化和新特性
Shell基础概念和变量
I copied the bottom of the liquidated NFT, but was locked by opensea
Redis —— 基础篇
[ecmascript6] symbol and its related use
[ecmascript6] function and its related use
Better and more modern terminal tools than xshell!
Parent and child of treeselect
无法连接服务器怎么办(原始服务器找不到目标资源)
接口调不通,如何去排查?没想到10年测试老鸟栽在这道面试题上