uva1572--self-set (World Final 2013, graph theory model)

Source: Internet
Author: User

///////////////////////////////////////////////////////////////////////////////////////////////////////
tt2767
Disclaimer: This document is subject to the following agreement free reprint-non-commercial-non-derivative-retention Attribution | Creative Commons by-nc-nd 3.0
To view the update and discussion of this article, please click here: http://blog.csdn.net/tt2767
Link is deleted please Baidu: CSDN tt2767
///////////////////////////////////////////////////////////////////////////////////////////////////////

This question is worth learning:
1. Enter the matching code very beautifully!
2. Map the a+,a-into 2n,2n+1 and then reverse it by (2n) ^1 = 2n+1, (2n+1) ^1 = 2n, and have to say it is very subtle!

The puzzle: Since the square is infinite, the link number and other extensible numbers on the linked square as nodes, the linked square as the edge, looking for the secondary graph of the ring.
Examples in the topic:
A-|->->->->->->->->->->a+|->->->->->->->-> (A+,A+,00)
The node to connect ———— two square connection points ———— the other nodes of the square being linked

#include <cstdio>#include <cstring>intg[ -][ -];intvis[ -];//Turn a+-into 2n and 2n+1intID (CharXChary);//This function indicates that an interface is connected to the other interfaces that are converted into the U//Use (2n) ^1 = 2n+1, (2n+1) ^1 = 2n to invertvoidContCharX1,CharX2,CharY1,Chary2);BOOLDfsintu);BOOLCyc ();intMain () {intN while(scanf("%d", &n) = =1&& N) {memsetG' + ',sizeof(G));memset(Vis,0,sizeof(VIS)); for(inti =0; I < n; i++) {Chars[9];scanf('%s ', s); for(intj =0; J <4; J + +) for(intK =0; K <4; k++)if(j! = k)//For each edge connected to other non-self edgesCont (s[j*2],s[j*2+1],s[k*2],s[k*2+1]); }if(Cyc ())puts("unbounded");//This is the infinite ...         Else            puts("bounded"); }return 0;}intID (CharXCharY) {return(X-' A ')*2+ (y = =' + '?0:1);}voidContCharX1,CharX2,CharY1,Chary2) {if(X1 = =' 0 '|| Y1 = =' 0 ')return;intU = ID (x1,x2) ^1;intv = ID (y1,y2); g[u][v]++;}BOOLDfsintu) {Vis[u] =-1; for(inti =0; I < the; i++) {if(G[u][i]) {if(Vis[i] <0)return true;Else if(!vis[i] && dfs (i))return true; }} Vis[u] =1;return false;}BOOLCyc () { for(inti =0; I < the; i++)if(!vis[i] && dfs (i))return true;return false;}

Copyright NOTICE: This article for Bo Master original article, allow non-commercial reprint, reprint must famous author (CSDN tt2767) and this blog link: http://blog.csdn.net/tt2767.

uva1572--self-set (World Final 2013, graph theory model)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.