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

UVA 1572 Self-Assembly

时间:2015-07-30 23:24:11      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

以颜色为节点,同一个方块上的颜色连边。。。看是不是有环。。。如果有环就可以无限延长。。。。

Self-Assembly

Problem ID: assemblyTime limit: 5 secondsMemory limit: 1024 MB

DIFFICULTY

3.7

Automatic Chemical Manufacturing is experimenting with a process called self-assembly. In this process, molecules with natural affinity for each other are mixed together in a solution and allowed to spontaneously assemble themselves into larger structures. But there is one problem: sometimes molecules assemble themselves into a structure of unbounded size, which gums up the machinery.

You must write a program to decide whether a given collection of molecules can be assembled into a structure of unbounded size. You should make two simplifying assumptions: 1) the problem is restricted to two dimensions, and 2) each molecule in the collection is represented as a square. The four edges of the square represent the surfaces on which the molecule can connect to other compatible molecules.

In each test case, you will be given a set of molecule descriptions. Each type of molecule is described by four two-character connector labels that indicate how its edges can connect to the edges of other molecules. There are two types of connector labels:

  • An uppercase letter (A,,Z) followed by + or ?. Two edges are compatible if their labels have the same letter but different signs. For example, A+ is compatible with A? but is not compatible with A+ or B?.

  • Two zero digits 00. An edge with this label is not compatible with any edge (not even with another edge labeled 00).

Assume there is an unlimited supply of molecules of each type, which may be rotated and reflected. As the molecules assemble themselves into larger structures, the edges of two molecules may be adjacent to each other only if they are compatible. It is permitted for an edge, regardless of its connector label, to be connected to nothing (no adjacent molecule on that edge).

Figure 1 shows an example of three molecule types and a structure of bounded size that can be assembled from them (other bounded structures are also possible with this set of molecules).

技术分享 技术分享
Figure 1: Illustration of Sample Input 1.


Input

The input consists of a single test case. A test case consists of two lines. The first contains an integer n (1n40000) indicating the number of molecule types. The second line contains n eight-character strings, each describing a single type of molecule, separated by single spaces. Each string consists of four two-character connector labels representing the four edges of the molecule in clockwise order.

Output

Display the word unbounded if the set of molecule types can generate a structure of unbounded size. Otherwise, display the word bounded.

Sample Input 1 Sample Output 1
3
A+00A+A+ 00B+D+A- B-C+00C+
bounded
Sample Input 2 Sample Output 2
1
K+K-Q+Q-
unbounded

Download the sample data files

Source: ACM International Collegiate Programming Contest World Finals 2013. License: Restricted, used with permission


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define prt(k) cout<<#k" = "<<k<<endl
const int m = 26;
 
int f(string a)
{
        if (a=="00") return -1;
        int c = a[0] - 'A';
        return 2 * c + (a[1]=='+');
}
int mp[77];
int du[77];
vector<int> g[77];
void add(int u, int v)
{
        du[v]++;
    //    printf("%d --> %d\n", u, v);
        g[u].push_back(v);
}
bool gao()
{
        queue<int> q;
        for (int i=0;i<m;i++) if(du[i]==0) q.push(i);
        int cnt = 0;
        while (!q.empty()) {
                int u = q.front(); q.pop();
                cnt++;
                for (int v : g[u]) {
                        du[v]--;
                        if (du[v]==0) q.push(v);
                }
        }
        return cnt==m;
}
int main()
{
        int n;
        while (scanf("%d", &n)==1) {
                memset(mp, 0, sizeof mp);
                memset(du, 0, sizeof du);
                bool g[75][75];
                 memset(g, 0, sizeof g);
              //  for (int i=0;i<55;i++) g[i].clear();
                for (int i=0;i<n;i++) {
                        char buf[10];
                        scanf("%s", buf);
                        string s(buf);
                        int t[55];
                        for (int j=0;j<4;j++)
                                t[j] = f(s.substr(j*2, 2));//,prt(t[j]);
 
                       
                        for (int j=0;j<4;j++)
                        for (int k=0;k<4;k++) if (j - k && t[j]!=-1 && t[k]!=-1) {
                                g[t[j]][t[k]^1] = true;
                        }
                }
                n = 52;
                for(int k = 0; k < n; k++) {
                for(int i = 0; i < n; i++)
                                for(int j = 0; j < n; j++)
                                        g[i][j] |= g[i][k]&&g[k][j];
                }
                bool f = 0;
                for (int i=0;i<n;i++) f|=g[i][i];
                puts(!f ? "bounded" : "unbounded");
        }
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

UVA 1572 Self-Assembly

标签:

原文地址:http://blog.csdn.net/oilover/article/details/47157061

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