(打的超级差!!!!!!!!)Codeforces Round #648 (Div. 2)

A Matrix Game

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).

Example
input
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
output
Vivek
Ashish
Vivek
Ashish
Note
For the first case: One possible scenario could be: Ashish claims cell (1,1), Vivek then claims cell (2,2). Ashish can neither claim cell (1,2), nor cell (2,1) as cells (1,1) and (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), 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), Vivek will have no moves left.
题意:两个人玩游戏,给你个矩阵,每次一个人必须得选择出来一个点,这个点所处的那一行那一列,必须都是0,选完之后自然就变成1,否则就输了,问你谁能赢。
思路:去遍历一遍就行了。

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define inf 0x3f3f3f3f3f;
typedef long long ll;
int a[55][55];
int b[55];
int c[55];
int main()
{
	int t; cin >> t;
	while (t--)
	{
		int m, n;
		cin >> n >> m;
		memset(b, 0, sizeof b);
		memset(c, 0, sizeof c);
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= m; j++)
			{
				cin >> a[i][j];
				if (a[i][j] == 1)
				{
					b[i] = 1; c[j] = 1;
				}
			}
		}
		int s = 0;
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= m; j++)
			{
				if (c[j] == 0 && b[i] == 0)
				{
					s++;
					c[j] = 1; b[i] = 1;
				}

			}
		}
		if (s % 2 == 0)
		{
			cout << "Vivek" << endl;
		}
		else
		{
			cout << "Ashish" << endl;
		}
	}
}

B.Trouble Sort

Ashish has n elements arranged in a line.

These elements are represented by two integers ai — the value of the element and bi — the type of the element (there are only two possible types: 0 and 1). He wants to sort the elements in non-decreasing values of ai.

He can perform the following operation any number of times:

Select any two elements i and j such that bi≠bj and swap them. That is, he can only swap two elements of different types in one move.
Tell him if he can sort the elements in non-decreasing values of ai after performing any number of operations.

Input
The first line contains one integer t (1≤t≤100) — the number of test cases. The description of the test cases follows.

The first line of each test case contains one integer n (1≤n≤500) — the size of the arrays.

The second line contains n integers ai (1≤ai≤105) — the value of the i-th element.

The third line containts n integers bi (bi∈{0,1}) — the type of the i-th element.

Output
For each test case, print “Yes” or “No” (without quotes) depending on whether it is possible to sort elements in non-decreasing order of their value.

You may print each letter in any case (upper or lower).

Example
input
5
4
10 20 20 30
0 1 0 1
3
3 1 2
0 1 1
4
2 2 4 8
1 1 1 1
3
5 15 4
0 0 0
4
20 10 100 50
1 0 0 1
output
Yes
Yes
Yes
No
Yes
Note
For the first case: The elements are already in sorted order.

For the second case: Ashish may first swap elements at positions 1 and 2, then swap elements at positions 2 and 3.

For the third case: The elements are already in sorted order.

For the fourth case: No swap operations may be performed as there is no pair of elements i and j such that bi≠bj. The elements cannot be sorted.

For the fifth case: Ashish may swap elements at positions 3 and 4, then elements at positions 1 and 2.
题意:就是想办法把它排成不下降序列看看能不能行,但在交换的时候 b 【i】不能一样
思路:其实你仔细想想 如果同时有1 0的话是不是所有的数字都能交换了,所以这个题目 就可以这样去判断 如果 既有1 也有0 那么这个肯定yes 如果不同时存在那就判断是不是不下降序列就行了啊

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define inf 0x3f3f3f3f3f;
typedef long long ll;
int a[50000], b[5000];
int main()
{
	int t; cin >> t;
	while (t--)
	{
		int q = 0, w = 0;
		int n; cin >> n;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		for (int i = 0; i<n; i++)
		{
			cin >> b[i];
			if (b[i] == 0)
				q++;
			else w++;
		}
		if(q!=0&&w!=0)
			cout << "Yes" << endl;
		else
		{
			int u = 0;
			for (int i = 1; i < n; i++)
			{
				if (a[i]<a[i - 1])
				{
					u = 1;
					break;
				}
			}
			if(u==0)
				cout << "Yes" << endl;
			else 
				cout << "No" << endl;
		}



	

	}

}

Codeforces Round #648 (Div. 2)–C. Rotation Matching

After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let’s call them a and b.

Note that a permutation of n elements is a sequence of numbers a1,a2,…,an, in which every number from 1 to n appears exactly once.

The message can be decoded by an arrangement of sequence a and b, such that the number of matching pairs of elements between them is maximum. A pair of elements ai and bj is said to match if:

i=j, that is, they are at the same index.
ai=bj
His two disciples are allowed to perform the following operation any number of times:

choose a number k and cyclically shift one of the permutations to the left or right k times.
A single cyclic shift to the left on any permutation c is an operation that sets c1:=c2,c2:=c3,…,cn:=c1 simultaneously. Likewise, a single cyclic shift to the right on any permutation c is an operation that sets c1:=cn,c2:=c1,…,cn:=cn−1 simultaneously.

Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.

Input
The first line of the input contains a single integer n (1≤n≤2⋅105) — the size of the arrays.

The second line contains n integers a1, a2, …, an (1≤ai≤n) — the elements of the first permutation.

The third line contains n integers b1, b2, …, bn (1≤bi≤n) — the elements of the second permutation.

Output
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.

Examples
inputCopy
5
1 2 3 4 5
2 3 4 5 1
outputCopy
5
inputCopy
5
5 4 3 2 1
1 2 3 4 5
outputCopy
1
inputCopy
4
1 3 2 4
4 2 3 1
outputCopy
2
Note
For the first case: b can be shifted to the right by k=1. The resulting permutations will be {1,2,3,4,5} and {1,2,3,4,5}.

For the second case: The operation is not required. For all possible rotations of a and b, the number of matching pairs won’t exceed 1.

For the third case: b can be shifted to the left by k=1. The resulting permutations will be {1,3,2,4} and {2,3,1,4}. Positions 2 and 4 have matching pairs of elements. For all possible rotations of a and b, the number of matching pairs won’t exceed 2.
题意:给你两个数组 ,每个数组元素不重复,可以平移b数组,让a b 数组 相同位置上相等的数最多。
思路:当时在做的时候 想暴力肯定是不行,肯定有一些技巧,太可惜了,
要利用好 数组不重复,先以c[a[i]]=i;这样来存位置,之后在b数组中,平移的距离dis=c[b[i]]-i;当然可能为负,为负就加n,然后 你以距离为角标 让d[dis]++;
因为平移距离一样说明相等的数就多呗

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define inf 0x3f3f3f3f3f;
typedef long long ll;
int a[210000], b[210000];
int c[210000];
int d[210000];
int main()
{
	
		memset(a, 0, sizeof a);
		memset(b, 0, sizeof b);	memset(c, 0, sizeof c);	memset(d, 0, sizeof d);
		int n; cin >> n;
		for (int i = 1; i <= n; i++)
		{
			cin >> a[i];
			c[a[i]] = i;
		}
		for (int i = 1; i <= n; i++)
		{
			cin >> b[i];
			int u = c[b[i]]-i;
			if (u < 0)
				u = n + u;
			d[u]++;
		}
		int maxx = 0;
		for (int i = 0; i <= n; i++)
		{
			maxx = max(maxx, d[i]);
		}
		cout << maxx << endl;
	

}

你可能感兴趣的:((打的超级差!!!!!!!!)Codeforces Round #648 (Div. 2))