poj 3660 Cow Contest
来源:互联网 发布:parsley.js 手册 编辑:程序博客网 时间:2024/06/05 20:46
看了题解才知道,原来floyd不止是用来求最短路的......
用floyd,如果i和j有关则a[i][j]=1,否则为-1;
能得出一个点的绝对排名的充要条件是这个点和其他每个点都有关(直接或间接)。
最后遍历每一个点,如果存在一个点和这个点没有关系,那么这个点就是一个无关点,最后用n-无关点个数就是答案。
#include <iostream>#include<stdio.h>#include<cstring> using namespace std; int a[105][105];//表示两者间是否有关,1有关,-1无关 int n,m; void floyd(){ for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int k=1;k<=n;k++){ if(a[j][k]==-1&&a[j][i]+a[i][k]>0) a[j][k]=1; } } int main() { int count=0; memset(a,-1,sizeof(a)); for(int i=1;i<=n;i++) a[i][i]=1; scanf("%d %d",&n,&m); for(int i=1;i<=m;i++){ int temp1,temp2; scanf("%d %d",&temp1,&temp2); a[temp1][temp2]=1; } floyd(); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++){ if(i==j) continue; if((a[i][j]==-1)&&(a[j][i]==-1)) { count++; break; } } printf("%d\n",n-count); return 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
- hdu 1158 Employment Planning
- poj 1018 Communication System
- hdu 1827 Summer Holiday
- hdu 1295 Move Move Look
- poj 2367 Genealogical tree
- poj 3660 Cow Contest
- poj 3553 Task schedule
- C++ 简单实现HTTP GET/POST 请求
- poj 2488 A Knight's Journey
- 问题集2
- How compiler works
- AjaxPro版自动完成(Autocomplete)功能实现
- Silverlight访问页面dom元素
- DDL 数据定义语言