Matrix Game HYSBZ-1059 (Max Stream)

Source: Internet
Author: User

1059: [ZJOI2007] Matrix game time limit: ten Sec Memory Limit: 162 MB
Submit: 6266 Solved: 3065
[Submit] [Status] [Discuss] Description Small q is a very clever kid, besides chess, he also likes to play a computer puzzle game-matrix game. The matrix game is carried out in a n*n black-and-white phalanx (as in chess, except that the color is random). You can do two operations on the Matrix at a time: Select any two rows of the matrix, swap the columns of the two lines (that is, the color of the swap grid): Select any column of the matrix, swap the two columns (that is, swap the color of the corresponding lattice) the target of the game, that is, by several operations, the main diagonal The upper-left corner of the line to the lower-right corner of the grid is black. For some of the levels, the small q can not be solved, so that he began to wonder whether these levels are simply no solution!! So little Q decided to write a program to determine whether these levels have a solution. The first line of Input contains an integer t, which represents the number of groups of data. Next contains the T-group data, each set of data first behaves as an integer n, representing the size of the Phalanx; next n behaves as a n*n 01 matrix (0 for White and 1 for black). Output

The output file should contain a T line. For each set of data, if the level has a solution, the output line is yes;

Sample Input2
2
0 0
0 1
3
0 0 1
0 1 0
1 0 0Sample OutputNo
Yes
"Data Size"
For 100% of data, n≤200 parsing:Enter the time encountered 1 will be this line and the 1 column number corresponding to the line number of the edge but not the original line number to + Nthe idea of the dichotomy is that the original line number and s are connected n + the original line number and T are connected to a capacity of 1and run it again. dinic if max flow = = N Yes otherwise no
#include <iostream>#include<cstdio>#include<sstream>#include<cstring>#include<map>#include<cctype>#include<Set>#include<vector>#include<stack>#include<queue>#include<algorithm>#include<cmath>#include<bitset>#defineRap (i, A, n) for (int i=a; i<=n; i++)#defineRep (I, A, n) for (int i=a; i<n; i++)#defineLap (I, a, n) for (int i=n; i>=a; i--)#defineLEP (i, A, n) for (int i=n; i>a; i--)#defineRD (a) scanf ("%d", &a)#defineRlld (a) scanf ("%lld", &a)#defineRC (a) scanf ("%c", &a)#defineRS (a) scanf ("%s", a)#definePD (a) printf ("%d\n", a);#definePlld (a) printf ("%lld\n", a);#definePC (a) printf ("%c\n", a);#definePS (a) printf ("%s\n", a);#defineMOD 2018#defineLL Long Long#defineULL unsigned long Long#definePair Pair<int, int>#defineMem (A, B) memset (A, B, sizeof (a))#define_ Ios_base::sync_with_stdio (0), Cin.tie (0)//freopen ("1.txt", "R", stdin);using namespacestd;Const intMAXN =100010, INF =0x7fffffff, Ll_inf =0x7fffffffffffffff;intHEAD[MAXN], CUR[MAXN], D[MAXN], VIS[MAXN];intN, m, s, T, CNT;structnode{intu, V, C, next;} NODE[MAXN<<1];voidAdd_ (intUintVintc) {node[cnt].u=u; NODE[CNT].V=v; NODE[CNT].C=C; Node[cnt].next=Head[u]; Head[u]= cnt++;}voidAddintUintVintW)    {add_ (U, V, W); Add_ (V, u,0);}BOOLBFs () {Queue<int>Q; Mem (d,0);    Q.push (s); D[s]=1;  while(!Q.empty ()) {        intU =Q.front ();        Q.pop ();  for(inti = Head[u]; I! =-1; i =Node[i].next) {Node E=Node[i]; if(!D[E.V] && e.c >0) {D[E.V]= D[u] +1;                Q.push (E.V); if(e.v = = t)return 1; }        }    }    returnD[T]! =0;}intDfsintUintcap) {    intRET =0; if(U = = T | | cap = =0)        returncap;  for(int&i = Cur[u]; I! =-1; i =Node[i].next) {Node E=Node[i]; if(D[E.V] = = D[e.u] +1&& e.c >0)        {            intV =dfs (e.v, min (Cap, e.c)); NODE[I].C-=V; Node[i^1].C + =V; RET+=V; Cap-=V; if(Cap = =0) Break; }    }    if(Cap >0) D[u] =-1; returnret;}intDinic (intu) {    intAns =0;  while(BFS ()) {//cout << 111 << Endl;memcpy (cur, head,sizeof(head)); Ans+=dfs (U, INF); }    returnans;}voidinit () {mem (head,-1); CNT=0;}CharSTR[MAXN];intMain () {intT; CIN>>T;  while(t--) {init (); intx; CIN>>N; S=0, t =2* n +1;  for(inti =1; I <= N; i++)        {             for(intj =1; J <= N; J + +) {rd (x); if(x = =1) {Add (i, n+ J,1); }} Add (S, I,1); }         for(inti =1; I <= N; i++) Add (n+ I, T,1); if(Dinic (s) = =N) cout<<"Yes"<<Endl; Elsecout<<"No"<<Endl; }    return 0;}

1059: [ZJOI2007] Matrix game time limit: ten Sec Memory Limit: 162 MB
Submit: 6266 Solved: 3065
[Submit] [Status] [Discuss] Description Small q is a very clever kid, besides chess, he also likes to play a computer puzzle game-matrix game. The matrix game is carried out in a n*n black-and-white phalanx (as in chess, except that the color is random). You can do two operations on the Matrix at a time: Select any two rows of the matrix, swap the columns of the two lines (that is, the color of the swap grid): Select any column of the matrix, swap the two columns (that is, swap the color of the corresponding lattice) the target of the game, that is, by several operations, the main diagonal The upper-left corner of the line to the lower-right corner of the grid is black. For some of the levels, the small q can not be solved, so that he began to wonder whether these levels are simply no solution!! So little Q decided to write a program to determine whether these levels have a solution. The first line of Input contains an integer t, which represents the number of groups of data. Next contains the T-group data, each set of data first behaves as an integer n, representing the size of the Phalanx; next n behaves as a n*n 01 matrix (0 for White and 1 for black). Output

The output file should contain a T line. For each set of data, if the level has a solution, the output line is yes;

Sample Input2
2
0 0
0 1
3
0 0 1
0 1 0
1 0 0Sample OutputNo
Yes
"Data Size"
For 100% of data, n≤200

Matrix Game HYSBZ-1059 (Max Stream)

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.