Aizu - 2555 Everlasting Zero 模拟

 Aizu - 2555 Everlasting Zero

 

题意:学习技能,每个技能有不同的要求,问能否学习全部特殊技能

思路:枚举每两个技能,得到他们的先后学习关系,如果两个都不能先学的话就是No了,如果A>B,B>C,但是并没有A>C那么这种情况也是不允许的了,我过的也是比较惊险。

  1 #pragma comment(linker, "/STACK:1000000000")
  2 #include <bits/stdc++.h>
  3 #define LL long long
  4 #define INF 0x3f3f3f3f
  5 #define IN freopen("in.txt","r",stdin);
  6 #define OUT freopen("out.txt", "w", stdout);
  7 using namespace std;
  8 #define MAXN 105
  9 #define MAXM 25005
 10 
 11 bool dayu[MAXN][MAXN], vis[MAXN][MAXN][MAXN];
 12 int in[MAXN];
 13 queue<int> Q;
 14 int gao[MAXN][MAXN], di[MAXN][MAXN];
 15 int main()
 16 {
 17         //IN;
 18         int m, n, k, x, y;
 19         char s[5];
 20         scanf("%d%d", &m, &n);
 21         memset(di, 0, sizeof(di));
 22         memset(gao, INF, sizeof(gao));
 23         for(int i = 1; i <= m; i++){
 24             scanf("%d", &k);
 25             for(int j = 1; j <= k; j++){
 26                 scanf("%d%s%d", &x, &s, &y);
 27                 if(s[0] == '<'){
 28                     gao[i][x] = min(gao[i][x], y);
 29                 }
 30                 else{
 31                     di[i][x] = max(di[i][x], y);
 32                 }
 33             }
 34         }
 35         for(int i = 1; i <= m; i++){
 36             for(int j = 1; j <= n; j++){
 37                 if(di[i][j] > gao[i][j]){
 38                     printf("No\n");
 39                     return 0;
 40                 }
 41             }
 42         }
 43         memset(dayu, 0, sizeof(dayu));
 44         memset(in, 0, sizeof(in));
 45         for(int i = 1; i <= m; i++){
 46             for(int j = 1; j <= m; j++){
 47                 if(i == j) continue;
 48                 bool flag = false;
 49                 for(int k = 1; k <= n; k++){
 50                     if(di[i][k] > gao[j][k]){
 51                         flag = true;
 52                         break;
 53                     }
 54                 }
 55                 if(!flag){
 56                     dayu[i][j] = true;
 57                     in[j]++;
 58                 }
 59             }
 60         }
 61         for(int i = 1; i <= m; i++){
 62             for(int j = 1; j <= m; j++){
 63                 for(int k = 1; k <= m; k++){
 64                     if(i == j || i == k || j == k) continue;
 65                     if(dayu[i][j] && dayu[i][k] && dayu[k][j]){
 66                         vis[i][j][k] = true;
 67                         vis[i][k][j] = true;
 68                         vis[j][i][k] = true;
 69                         vis[j][k][i] = true;
 70                         vis[k][i][j] = true;
 71                         vis[k][j][i] = true;
 72                     }
 73                 }
 74             }
 75         }
 76         for(int i = 1; i <= m; i++){
 77             for(int j = 1; j <= m; j++){
 78                 for(int k = 1; k <= m; k++){
 79                     if(i == j || i == k || j == k) continue;
 80                     if(vis[i][j][k]) continue;
 81                     printf("No\n");
 82                     return 0;
 83                 }
 84             }
 85         }
 86         for(int i = 1; i <= m; i++){
 87             for(int j = 1; j <= m; j++){
 88                     if(i == j) continue;
 89                 if(!dayu[i][j] && !dayu[j][i]){
 90                     printf("No\n");
 91                     return 0;
 92                 }
 93             }
 94         }
 95         printf("Yes\n");
 96         return 0;
 97        /* memset(vis, 0, sizeof(vis));
 98         while(!Q.empty()){
 99             Q.pop();
100         }
101         for(int i = 1; i <= m; i++){
102             bool flag = false;
103             for(int j = 1; j <= m; j++){
104                 if(dayu[i][j] || i == j) continue;
105                 flag = true;
106                 break;
107             }
108             if(!flag){
109                 Q.push(i);
110                 vis[i] = true;
111             }
112         }
113         int ans = 0;
114 
115         while(!Q.empty()){
116             int s = Q.front();
117             vis[s] = true;
118             ans++;
119             Q.pop();
120             for(int i = 1; i <= m; i++){
121                 if(dayu[s][i]){
122                     in[i]--;
123                     if(in[i] == 0 && !vis[i]){
124                         Q.push(i);
125                     }
126                 }
127             }
128         }
129         if(ans == m){
130             printf("Yes\n");
131         }
132         else{
133             printf("No\n");
134         }*/
135     return 0;
136 }

 

posted on 2015-08-22 23:44  张济  阅读(181)  评论(0编辑  收藏  举报

导航