Bzoj1059| Matrix Game

Source: Internet
Author: User

Description
Little 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.
Input
The first line 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 Input

2
0 0
0 1
3
0 0 1
0 1 0
1 0 0
Sample Output
No
Yes
"Data Size"
for 100% of data, n≤200

Analysis 1: First we want to know that in the same row or the same column of points, no matter how the interchange will also be in the same row or column. In fact, the above sentence and this question is OK ... We can understand that we want to have an edge between NX and NY, with n points vertical and n points. Using the meaning of the topic, we can know that once there is a pair of sides we can move it to the diagonal, as long as there are n pairs, we can make a full 1 diagonal.

Well, I guess no one can read analysis 1, so ...

Analysis 2: Consider matching this kind of thing. We match the horizontal ordinate of the read-in adjacency matrix as two piles of points. It is clear that the area of influence of each edge is the row and column in which it resides. We can move it to the diagonal and solve the problem.

#include <iostream>#include<cstdio>#include<cmath>#include<cstring>using namespacestd;intlk[201],y[201];intmap[201][201];intn,t;BOOLFindintx) {     for(intI=1; i<=n; i++)    {        if(!y[i] &&Map[x][i]) {Y[i]=1; if(!lk[i] | |find (Lk[i])) {Lk[i]=x; return 1; }        }    }    return 0;}voidWork () { for(intI=1; i<=n; i++) {memset (Y,0,sizeof(y)); if(!find (i)) {cout <<"No"<< Endl;return; }} cout<<"Yes"<<Endl; return;}intMain () {CIN>>T;  for(intk=1; k<=t; k++) {cin>>N; memset (Map,0,sizeof(map)); memset (LK,0,sizeof(LK));  for(intI=1; i<=n; i++)             for(intj=1; j<=n; J + +) Cin>>Map[i][j];    Work (); }    return 0;}

Bzoj1059| Matrix Game

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.