Codeforces648div2A
原题:
Ashish and Vivek play a game on a matrix consisting of n rows and m columns, where they take turns claiming cells. Unclaimed cells are represented by 0, while claimed cells are represented by 1. The initial state of the matrix is given. There can be some claimed cells in the initial state.
In each turn, a player must claim a cell. A cell may be claimed if it is unclaimed and does not share a row or column with any other already claimed cells. When a player is unable to make a move, he loses and the game ends.
If Ashish and Vivek take turns to move and Ashish goes first, determine the winner of the game if both of them are playing optimally.
Optimal play between two players means that both players choose the best possible strategy to achieve the best possible outcome for themselves.
Input
The first line consists of a single integer t (1≤t≤50) — the number of test cases. The description of the test cases follows.
The first line of each test case consists of two space-separated integers n, m (1≤n,m≤50) — the number of rows and columns in the matrix.
The following n lines consist of m integers each, the j-th integer on the i-th line denoting ai,j (ai,j∈{0,1}).
Output
For each test case if Ashish wins the game print “Ashish” otherwise print “Vivek” (without quotes).
思路:模拟,记录下每一行、每一列是否可选
ACcodes
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
using namespace std;
int a[60][60];
void q()
{
int n;
scanf("%d",&n);
long long int a=0;
long long int tot = (1<<(n+1)) - 2;
a = (1<<n) + (1<<(n/2)) -2;
cout << abs(tot-2*a) << endl;
}
int main()
{
int test=1;
scanf("%d",&test);
while(test--) {
int n,m;cin>>n>>m;
int cnt1=0,cnt2=0;
for(int i=0;i<n;i++) {
int flag = 0;
for(int j=0;j<m;j++) {
int x;cin>>x;
if(x == 1)
flag = 1;
a[i][j] = x;
}
if(flag == 0) cnt1++;
}
for(int i=0;i<m;i++) {
int flag = 0;
for(int j=0;j<n;j++) {
if(a[j][i] == 1) flag = 1;
}
if(flag == 0) cnt2++;
}
int cnt = min(cnt1,cnt2);
if(cnt%2==0) {
cout<<"Vivek" << endl;
} else {
cout<<"Ashish" << endl;
}
}
return 0;
}