Description
Input
Output
Sample Input
3
A+00A+A+ 00B+D+A- B-C+00C+
Sample Output
bounded
Hint
题解
1 //It is made by Awson on 2017.9.19 2 #include <map> 3 #include <set> 4 #include <cmath> 5 #include <ctime> 6 #include <queue> 7 #include <stack> 8 #include <cstdio> 9 #include <string> 10 #include <vector> 11 #include <cstdlib> 12 #include <cstring> 13 #include <iostream> 14 #include <algorithm> 15 #define LL long long 16 #define Max(a, b) ((a) > (b) ? (a) : (b)) 17 #define Min(a, b) ((a) < (b) ? (a) : (b)) 18 #define Abs(a) ((a) < 0 ? (-(a)) : (a)) 19 using namespace std; 20 21 int n; 22 23 int getnum(char x, char y) { 24 if (x == '0') return 52; 25 return x-'A'+26*(y == '+'); 26 } 27 void work() { 28 char ch[10]; 29 bool mp[100][100] = {0}; 30 int in[100] = {0}; 31 for (int T = 1; T <= n; T++) { 32 scanf("%s", ch+1); 33 for (int i = 1; i <= 8; i += 2) 34 for (int j = 1; j <= 8; j += 2) 35 if (i != j) { 36 int x = getnum(ch[i], ch[i+1]); 37 int y = getnum(ch[j], ch[j+1]); 38 if (x == 52 || y == 52) continue; 39 if (y < 26) y += 26; 40 else y -= 26; 41 mp[x][y] = true; 42 } 43 } 44 for (int i = 0; i <= 52; i++) 45 for (int j = 0; j <= 52; j++) 46 if (mp[i][j]) in[j]++; 47 int cnt = 0; 48 queue<int>Q; 49 while (!Q.empty()) Q.pop(); 50 for (int i = 0; i <= 52; i++) 51 if (!in[i]) Q.push(i); 52 while (!Q.empty()) { 53 int u = Q.front(); Q.pop(); 54 cnt++; 55 for (int i = 0; i <= 52; i++) 56 if (mp[u][i]) { 57 in[i]--; 58 if (!in[i]) Q.push(i); 59 } 60 } 61 printf("%s ", cnt < 53 ? "unbounded" : "bounded"); 62 } 63 64 int main() { 65 freopen("gene.in", "r", stdin); 66 freopen("gene.out", "w", stdout); 67 while (~scanf("%d", &n)) 68 work(); 69 return 0; 70 }