当前位置:网站首页>Poj3275 ranking the cows
Poj3275 ranking the cows
2022-07-28 13:49:00 【bj_ hacker】
POJ3275 Ranking the Cows Answer key
subject
link
http://poj.org/problem?id=3275
Literal description
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
Code implementation
#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;
}
边栏推荐
- 使用 Fail2ban 保护 Web 服务器免受 DDoS 攻击
- 长封闭期私募产品再现 业内人士看法各异
- Realize the mutual value transfer between main window and sub window in WPF
- LyScript 获取上一条与下一条指令
- Rust 从入门到精通01-简介
- R语言使用dpois函数生成泊松分布密度数据、使用plot函数可视化泊松分布密度数据(Poisson distribution)
- R language uses dpois function to generate Poisson distribution density data and plot function to visualize Poisson distribution density data
- After finishing, help autumn move, I wish you call it an offer harvester
- 30天刷题计划(四)
- Lyscript get previous and next instructions
猜你喜欢

30天刷题计划(三)

Today's sleep quality record 75 points

Realize the mutual value transfer between main window and sub window in WPF

基于神经网络的帧内预测和变换核选择

7.依赖注入

Operator3-设计一个operator

微信小程序中自定义模板

微念“失去”李子柒的这一年

Intra prediction and transform kernel selection based on Neural Network

Can second uncle cure young people's spiritual internal friction?
随机推荐
org.apache.ibatis.exceptions.TooManyResultsException的异常排查过程
【架构】评分较高的三本微服务书籍的阅读笔记
力扣 2354. 优质数对的数目
R language ggplot2 visualization: visualize the scatter diagram and add text labels to the data points in the scatter diagram, using geom of ggrep package_ text_ The rep function avoids overlapping da
DDoS protection with iptables
Generation of tables and contingency tables (cross tables) of R language factor data: use the summary function to analyze the list, view the chi square test results, and judge whether the two factor v
C语言:顺序存储结构的快速排序
Can second uncle cure young people's spiritual internal friction?
数据库系统原理与应用教程(058)—— MySQL 练习题(二):单选题
酷炫操作预热!代码实现小星球特效
蓝桥集训(附加面试题)第七天
R语言使用lm函数构建多元回归模型(Multiple Linear Regression)、并根据模型系数写出回归方程、使用confint函数给出回归系数的95%置信区间
30天刷题计划(四)
C language: random number + quick sort
What if the server cannot be connected (the original server cannot find the target resource)
【安全】 阅读 RFC6749 及理解 Oauth2.0 下的授权码模式
No swagger, what do I use?
在 Kubernetes 中部署应用交付服务(第 1 部分)
Remember to use pdfbox once to parse PDF and obtain the key data of PDF
JWT login authentication + token automatic renewal scheme, well written!