标签:style blog http io color ar os java for
1. Bead 2 is heavier than Bead 1.
2. Bead 4 is heavier than Bead 3.
3. Bead 5 is heavier than Bead 1.
4. Bead 4 is heavier than Bead 2.
1 5 4 2 1 4 3 5 1 4 2
2
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 101; 18 bool g[maxn][maxn]; 19 int n,m; 20 void Floyd() { 21 for(int k = 1; k <= n; ++k) { 22 for(int i = 1; i <= n; ++i) { 23 if(g[i][k]) { 24 for(int j = 1; j <= n; ++j) { 25 if(!g[i][j]) g[i][j] = g[i][k]&&g[k][j]; 26 } 27 } 28 } 29 } 30 } 31 int main() { 32 int u,v,x,y,T; 33 scanf("%d",&T); 34 while(T--){ 35 scanf("%d %d",&n,&m); 36 memset(g,false,sizeof(g)); 37 for(int i = 0; i < m; ++i){ 38 scanf("%d %d",&u,&v); 39 g[u][v] = true; 40 } 41 Floyd(); 42 int ans = 0; 43 for(int i = 1; i <= n; ++i){ 44 x = y = 0; 45 for(int j = 1; j <= n; ++j){ 46 if(g[i][j]) x++; 47 if(g[j][i]) y++; 48 } 49 if(x > (n-1)>>1 || y > (n-1)>>1) ans++; 50 } 51 cout<<ans<<endl; 52 } 53 return 0; 54 }
标签:style blog http io color ar os java for
原文地址:http://www.cnblogs.com/crackpotisback/p/4071064.html