码迷,mamicode.com
首页 > 其他好文 > 详细

[测试题]gene

时间:2017-09-19 17:55:17      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:put   es2017   get   inpu   size   printf   continue   com   include   

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\n", 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 }

 

[测试题]gene

标签:put   es2017   get   inpu   size   printf   continue   com   include   

原文地址:http://www.cnblogs.com/NaVi-Awson/p/7552710.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!