恩,暴力解决。
参考了http://haipeng31.blog.163.com/blog/static/105623344201011984618863/
主要是changed变量的使用。
View Code
1 /* 2 ID: xjtuacm1 3 PROG: concom 4 LANG: C++ 5 */ 6 #include<iostream> 7 #include<stack> 8 #include<cstring> 9 #include<cstdio> 10 #include<queue> 11 #include<algorithm> 12 using namespace std; 13 14 const int CMAX = 100 + 1; 15 16 int comp[CMAX][CMAX]; 17 bool owns[CMAX][CMAX]; 18 19 int main(int argc, char *argv[]) 20 { 21 freopen("concom.in", "r", stdin); 22 #ifndef USACO 23 freopen("concom.out", "w", stdout); 24 #endif // USACO 25 26 memset(comp, 0, sizeof(comp)); 27 memset(owns, false, sizeof(owns)); 28 29 int n; 30 scanf("%d", &n); 31 while(n--) 32 { 33 int i, j; 34 scanf("%d %d", &i, &j); 35 scanf("%d", &comp[i][j]); 36 } 37 38 for(int i = 0; i!= CMAX; i++) 39 owns[i][i] = true; // First condition 40 41 for(int i = 0; i!= CMAX; i++) 42 for(int j = 0; j!= true; j++) 43 owns[i][j] = (comp[i][j] >= 50); // Second condition. This can be merged with third condition. 44 45 bool changed = true; 46 while(changed) 47 { 48 changed = false; 49 for(int i = 1; i!= CMAX; i++) 50 { 51 for(int j = 1; j!= CMAX; j++) 52 { 53 if(!owns[i][j]) 54 { 55 int sum = 0; 56 for(int k = 1; k!= CMAX; k++) 57 { 58 if(owns[i][k]) 59 sum += comp[k][j]; 60 } 61 62 if(sum >= 50) 63 { 64 owns[i][j] = true; 65 changed = true; 66 } 67 } 68 } 69 } 70 } 71 72 for(int i = 1; i!= CMAX; i++) 73 { 74 for(int j = 1; j!= CMAX; j++) 75 { 76 if(owns[i][j] && i!= j) 77 printf("%d %d\n", i, j); 78 } 79 } 80 81 return 0; 82 }
BTW,发现现在碰到暴力的题都有点儿不敢做了。。= =

浙公网安备 33010602011771号