CF(补题)

A. Matrix Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
Ashish and Vivek play a game on a matrix consisting of nn rows and mm columns, where they take turns claiming cells. Unclaimed cells are represented by 00, while claimed cells are represented by 11. 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.InputThe first line consists of a single integer tt (1≤t≤50)(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 nn, mm (1≤n,m≤50)(1≤n,m≤50) — the number of rows and columns in the matrix.The following nn lines consist of mm integers each, the jj-th integer on the ii-th line denoting ai,jai,j (ai,j∈{0,1})(ai,j∈{0,1}).OutputFor each test case if Ashish wins the game print “Ashish” otherwise print “Vivek” (without quotes)
ExampleInputCopy
4
2 2
0 0
0 0
2 2
0 0
0 1
2 3
1 0 1
1 1 0
3 3
1 0 0
0 0 0
1 0 0
OutputCopy
Vivek
Ashish
Vivek
Ashish
NoteFor the first case: One possible scenario could be: Ashish claims cell (1,1)(1,1)

, Vivek then claims cell (2,2)(2,2)

. Ashish can neither claim cell (1,2)(1,2)

, nor cell (2,1)(2,1)

as cells (1,1)(1,1)

and (2,2)(2,2)

are already claimed. Thus Ashish loses. It can be shown that no matter what Ashish plays in this case, Vivek will win. For the second case: Ashish claims cell (1,1)(1,1)

, the only cell that can be claimed in the first move. After that Vivek has no moves left.For the third case: Ashish cannot make a move, so Vivek wins.For the fourth case: If Ashish claims cell (2,3)(2,3)

, Vivek will have no moves left.
题意:当时比赛时给理解错了(将他理解成了,不相邻的地方才可以占领,对自己的粗心无语了),这是给了一个矩阵,找出可以占领的单元个数,也就是矩阵中的0变为1,那么这行和这列的所有0都可能再变成1,这样为已经占领,然后找出获胜方就行。
解题思路:看咯大佬的代码才发现自己的错误,然后理解题意后发现很简单,就是开始将矩阵中为1的行列给记下来,然后在找可以变为1的行列,然后进行占领,最终看可以占领的步数,为奇数还是偶数就解决了。
AC代码:

#include 
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
        {
            int n,m,flag=0;
            cin>>n>>m;
            int a[50][50]={0};
            int x[50]={0},y[50]={0};
            for(int i=0;i<n;i++)
            for(int j=0;j<m;j++){
                 cin>>a[i][j];
                 if(a[i][j]==1)
                 x[i]++,y[j]++;
            }
            for(int i=0;i<n;i++)
            for(int j=0;j<m;j++)
                if(x[i]==0&&y[j]==0)
                {
                    flag++;
                    x[i]++;
                    y[j]++;
                }
            if(flag%2==0) cout<<"Vivek"<<endl;
            else cout<<"Ashish"<<endl;
        }
    return 0;
}

你可能感兴趣的:(CF(补题))