Hdu 4594 difference (singular circle judgment + differential constraint)

Source: Internet
Author: User

Title Address: http://acm.hdu.edu.cn/showproblem.php?pid=4598

Train of thought: by test instructions know two points of the AI symbol is opposite, so if there is a singular circle, there must be no solution. Staining, Colour[i]==1 expressed as positive, colour[i]==2 expressed as negative. Since (b) the condition is sufficient and necessary, for the point in the diagram | A[I]-A[J] | >= T, for non-image midpoint | A[I]-A[J] | < T, i.e. | A[I]-A[J] | <= T-1. So the midpoint of the figure, if COLOUR[I]==1,A[I]-A[J] >= T, otherwise a[j]-a[i] >= T. In the case of a non-graph midpoint, if there is a negative ring in the graph, there is no solution.

#include <cstdio> #include <queue> #include <vector> #include <cstring> #include <iostream    > #include <algorithm> #define debuusing namespace std;const int t=1111;const int maxn=350;struct node{int v,w; Node (int v=0,int w=0): V (v), W (w) {}};int n;queue<int> q;vector<int> g[maxn];char st[maxn][maxn];int Map[max n][maxn];vector<node> g[maxn];int dist[maxn],v[maxn];int colour[maxn],tot[maxn];void Find (int x,int flag) {//    cout<<x<< "" <<flag<<endl;    Colour[x]=flag; for (int i=0; i<g[x].size (); i++) if (!colour[g[x][i]]) Find (G[x][i],3-flag);}    int check () {//cout<< "Flag" <<endl;    memset (colour,0,sizeof (colour));    for (int i=1; i<=n; i++) if (!colour[i]) Find (i,1);    cout<< "Flag" <<endl;    for (int i=1, i<=n; i++) for (int j=0; j<g[i].size (); j + +) if (Colour[i]==colour[g[i][j]]) return 0; return 1;} void make () {for (int i=0; i<=n; i++) g[i].cLear (); for (int i=1, i<=n; i++) for (int j=i+1; j<=n; J + +) {//cout<<st[i-1][j-1]<< "" &l            t;<colour[i]<<endl; if (st[i-1][j-1]== ' 1 ') {if (colour[i]==1) {//cout<<i<                    < "<<j<<" <<-T<<endl;                G[i].push_back (Node (j,-t)); } else {//cout<<j<< "" <<i<< "" <<-T<<                    Endl                G[j].push_back (Node (i,-t)); }} else {if (colour[i]==1) {//cout<                    <j<< "<<i<<" <<T-1<<endl;                G[j].push_back (Node (i,t-1)); } else {//cout<<i<< "" <<j<< "" <<t-1<&lt                    ; Endl; G[i].pusH_back (Node (j,t-1));        }}}/*for (int i=1; i<=n; i++) cout<<i<< "" <<colour[i]<<endl;            for (int i=1; i<=n; i++) {cout<<g[i].size () <<endl; for (int j=0; j<g[i].size (); j + +) cout<<i<< "" <<G[i][j].v<< "" &LT;&LT;G[I][J].W&L        t;<endl;    }*/}int solve () {make ();    cout<< "Flag" <<endl;    while (!q.empty ()) Q.pop ();    memset (tot,0,sizeof (tot));    memset (dist,0,sizeof (Dist));        for (int i=1; i<=n; i++) {v[i]=1;    Q.push (i);        } while (!q.empty ()) {int Now=q.front ();        cout<<now<<endl;        Q.pop (), v[now]=0;            for (int i=0; i<g[now].size (); i++) {int nt=g[now][i].v;                if (DIST[NT]&GT;DIST[NOW]+G[NOW][I].W) {DIST[NT]=DIST[NOW]+G[NOW][I].W;                if (!v[nt]); {v[nt]=1;                    Q.push (NT);                if (++tot[nt]>n) return 0; }}}} return 1;}    int main () {#ifdef debug Freopen ("In.in", "R", stdin); #endif//debug int t;    scanf ("%d", &t);        while (t--) {scanf ("%d", &n);        GetChar ();        memset (map,0,sizeof (MAP));        for (int i=0; i<=n; i++) g[i].clear ();            for (int i=0; i<n; i++) {scanf ("%s", St[i]);            cout<<st[i]<<endl;        for (int j=0; j<n; J + +) if (st[i][j]== ' 1 ') g[i+1].push_back (j+1);        } if (check () &&solve ()) printf ("yes\n");    else printf ("no\n"); } return 0;}



Hdu 4594 difference (singular circle judgment + differential constraint)

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.