POJ 3660 Cow Contest
来源:互联网 发布:室内设计案例优化 编辑:程序博客网 时间:2024/05/16 10:51
题意:有n个数,m个关系;接下来的关系就是表示a比b厉害,问你最后又多少个可以确定排名的了
分析:我的思路是先把他们的关系初始化为无限大,然后可以确定关系的为改为1,让后floyd,动态方程为w[i][j]=min(w[i][j],max(w[i][k],w[k][i]));最后把无限大的数变成0,最后求有多少个数是其他点到他的距离为s1,他到其他店的距离为s2, 如果s1+s2==n-1,cnt++;最后输出cnt;
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxm=1e3+10;const int inf=1<<29;int w[maxm][maxm];int n,m;int main(){ while(scanf("%d%d",&n,&m)!=EOF) { int i,j,k; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { w[i][j]=inf; } } int u,v; while(m--) { scanf("%d%d",&u,&v); w[u][v]=1; } for(k=1;k<=n;k++) { for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(i!=j&&k!=j&&i!=k) { w[i][j]=min(w[i][j],max(w[i][k],w[k][j])); } } } } for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(w[i][j]==inf) { w[i][j]=0; } } } int cnt=0; for(i=1;i<=n;i++) { int sum=0; for(j=1;j<=n;j++) { if(i!=j) { sum+=(w[i][j]+w[j][i]); } } // printf("%d\n",sum); if(sum==n-1) { cnt++; } } printf("%d\n",cnt); } return 0;}
0 0
- poj 3660 Cow Contest
- POJ 3660 Cow Contest
- POJ 3660 Cow Contest
- poj 3660 Cow Contest
- POJ-3660-Cow Contest
- poj-3660 cow contest
- POJ 3660 Cow Contest
- poj 3660 Cow Contest
- poj 3660 Cow Contest
- poj 3660 Cow Contest
- poj-3660 Cow Contest
- POJ 3660 Cow Contest
- POJ -- 3660 Cow Contest
- POJ 3660 Cow Contest
- poj 3660 Cow Contest
- POJ 3660 Cow Contest
- POJ 3660 Cow Contest
- POJ-3660 Cow Contest
- PL/SQL 程序设计简介
- 解读Android之HttpURLConnection
- HTML布局relative和absolute
- sqlite 数据库加密(SQLCipher)
- ViewController
- POJ 3660 Cow Contest
- Callable 和Future 接口使用
- OMCI协议二层功能的模型选择
- oracle 分析函数
- iOS 面试大全从简单到复杂(简单篇)
- 如何使用命令查看电脑开放的端口
- mac系统安装软件
- IOS 自动布局指南1 介绍(auto layout guide)
- JAVA高并发学习笔记(三) JMM(Java内存模型)