A. Card Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Two players decided to play one interesting card game.
There is a deck of nn cards, with values from 11 to nn. The values of cards are pairwise different (this means that no two different cards have equal values). At the beginning of the game, the deck is completely distributed between players such that each player has at least one card.
The game goes as follows: on each turn, each player chooses one of their cards (whichever they want) and puts on the table, so that the other player doesn't see which card they chose. After that, both cards are revealed, and the player, value of whose card was larger, takes both cards in his hand. Note that as all cards have different values, one of the cards will be strictly larger than the other one. Every card may be played any amount of times. The player loses if he doesn't have any cards.
For example, suppose that n=5n=5, the first player has cards with values 22 and 33, and the second player has cards with values 11, 44, 55. Then one possible flow of the game is:
The first player chooses the card 33. The second player chooses the card 11. As 3>13>1, the first player gets both cards. Now the first player has cards 11, 22, 33, the second player has cards 44, 55.
The first player chooses the card 33. The second player chooses the card 44. As 3<43<4, the second player gets both cards. Now the first player has cards 11, 22. The second player has cards 33, 44, 55.
The first player chooses the card 11. The second player chooses the card 33. As 1<31<3, the second player gets both cards. Now the first player has only the card 22. The second player has cards 11, 33, 44, 55.
The first player chooses the card 22. The second player chooses the card 44. As 2<42<4, the second player gets both cards. Now the first player is out of cards and loses. Therefore, the second player wins.
Who will win if both players are playing optimally? It can be shown that one of the players has a winning strategy.
Input
Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001≤t≤100). The description of the test cases follows.
The first line of each test case contains three integers nn, k1k1, k2k2 (2≤n≤100,1≤k1≤n−1,1≤k2≤n−1,k1+k2=n2≤n≤100,1≤k1≤n−1,1≤k2≤n−1,k1+k2=n) — the number of cards, number of cards owned by the first player and second player correspondingly.
The second line of each test case contains k1k1 integers a1,…,ak1a1,…,ak1 (1≤ai≤n1≤ai≤n) — the values of cards of the first player.
The third line of each test case contains k2k2 integers b1,…,bk2b1,…,bk2 (1≤bi≤n1≤bi≤n) — the values of cards of the second player.
It is guaranteed that the values of all cards are different.
Output
For each test case, output "YES" in a separate line, if the first player wins. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower).
Example
input
Copy
2
2 1 1
2
1
5 2 3
2 3
1 4 5
output
Copy
YES
NO
#include
using namespace std;
int n, x, m;
int main() {
ios::sync_with_stdio(0);
int te;
cin >> te;
while (te--) {
int a, b;
cin >> n >> a >> b;
int maxna = 0, maxnb = 0;
while (a--) {
int c; cin >> c;
maxna = max(maxna, c);
}
while (b--) {
int c; cin >> c;
maxnb = max(maxnb, c);
}
if (maxna >= maxnb) {
cout << "YES\n";
}
else {
cout << "NO\n";
}
}
return 0;
}
B. Interesting Subarray
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
For an array aa of integers let's denote its maximal element as max(a)max(a), and minimal as min(a)min(a). We will call an array aa of kk integers interesting if max(a)−min(a)≥kmax(a)−min(a)≥k. For example, array [1,3,4,3][1,3,4,3] isn't interesting as max(a)−min(a)=4−1=3<4max(a)−min(a)=4−1=3<4 while array [7,3,0,4,3][7,3,0,4,3] is as max(a)−min(a)=7−0=7≥5max(a)−min(a)=7−0=7≥5.
You are given an array aa of nn integers. Find some interesting nonempty subarray of aa, or tell that it doesn't exist.
An array bb is a subarray of an array aa if bb can be obtained from aa by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
Input
The first line contains integer number tt (1≤t≤100001≤t≤10000). Then tt test cases follow.
The first line of each test case contains a single integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the length of the array.
The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109) — the elements of the array.
It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105.
Output
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in aa.
Otherwise, output "YES" in a separate line. In the next line, output two integers ll and rr (1≤l≤r≤n1≤l≤r≤n) — bounds of the chosen subarray. If there are multiple answers, print any.
You can print each letter in any case (upper or lower).
Example
input
Copy
3
5
1 2 3 4 5
4
2 0 1 9
2
2019 2020
output
Copy
NO
YES
1 4
NO
#include
using namespace std;
int n, x, m;
int k[200010];
int main() {
ios::sync_with_stdio(0);
int te;
cin >> te;
while (te--) {
cin >> n;
for (int i = 1; i <= n; i++)cin >> k[i];
int a = 0x3f3f3f3f, b = -1, c, d;
for (int i = 2; i <= n; i++) {
if (abs(k[i] - k[i - 1]) >= 2) {
a = -1;
c = i - 1, d = i; break;
}
}
if (a==-1) {
cout << "YES\n" << c << " " << d << "\n";
}
else cout << "NO\n";
}
return 0;
}
C. Make Good
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Let's call an array a1,a2,…,ama1,a2,…,am of nonnegative integer numbers good if a1+a2+⋯+am=2⋅(a1⊕a2⊕⋯⊕am)a1+a2+⋯+am=2⋅(a1⊕a2⊕⋯⊕am), where ⊕⊕ denotes the bitwise XOR operation.
For example, array [1,2,3,6][1,2,3,6] is good, as 1+2+3+6=12=2⋅6=2⋅(1⊕2⊕3⊕6)1+2+3+6=12=2⋅6=2⋅(1⊕2⊕3⊕6). At the same time, array [1,2,1,3][1,2,1,3] isn't good, as 1+2+1+3=7≠2⋅1=2⋅(1⊕2⊕1⊕3)1+2+1+3=7≠2⋅1=2⋅(1⊕2⊕1⊕3).
You are given an array of length nn: a1,a2,…,ana1,a2,…,an. Append at most 33 elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
Input
Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤100001≤t≤10000). The description of the test cases follows.
The first line of each test case contains a single integer nn (1≤n≤105)(1≤n≤105) — the size of the array.
The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109) — the elements of the array.
It is guaranteed that the sum of nn over all test cases does not exceed 105105.
Output
For each test case, output two lines.
In the first line, output a single integer ss (0≤s≤30≤s≤3) — the number of elements you want to append.
In the second line, output ss integers b1,…,bsb1,…,bs (0≤bi≤10180≤bi≤1018) — the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
Example
input
Copy
3
4
1 2 3 6
1
8
2
1 1
output
Copy
0
2
4 4
3
2 6 2
这道题通过异或的概念即可简单得出。
#include
using namespace std;
int n, x, m;
int k[200010];
int main() {
ios::sync_with_stdio(0);
int te;
cin >> te;
while (te--) {
cin >> n;
long long a = 0, b = 0;
for (int i = 1; i <= n; i++)
cin >> k[i], a += k[i], b ^= k[i];
cout << 2 << " " << b << " " << a + b << "\n";
}
return 0;
}
D. Strange Device
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is interactive.
We have hidden an array aa of nn pairwise different numbers (this means that no two numbers are equal). You can get some information about this array using a new device you just ordered on Amazon.
This device can answer queries of the following form: in response to the positions of kk different elements of the array, it will return the position and value of the mm-th among them in the ascending order.
Unfortunately, the instruction for the device was lost during delivery. However, you remember kk, but don't remember mm. Your task is to find mm using queries to this device.
You can ask not more than nn queries.
Note that the array aa and number mm are fixed before the start of the interaction and don't depend on your queries. In other words, interactor is not adaptive.
Note that you don't have to minimize the number of queries, and you don't need to guess array aa. You just have to guess mm.
Input
The first line contains two integers nn and kk (1≤k It is guaranteed that number mm satisfies 1≤m≤k1≤m≤k, elements a1,a2,…,ana1,a2,…,an of the array satisfy 0≤ai≤1090≤ai≤109, and all of them are different. Interaction You begin the interaction by reading nn and kk. To ask a question about elements on positions x1,x2,…,xkx1,x2,…,xk, in a separate line output ?? x1x1 x2x2 x3x3 ... xkxk Numbers in the query have to satisfy 1≤xi≤n1≤xi≤n, and all xixi have to be different. Don't forget to 'flush', to get the answer. In response, you will receive two integers pospos and aposapos — the position in the array aa of the mm-th in ascending order element among ax1,ax2,…,axkax1,ax2,…,axk, and the element on this position. In case your query is invalid or you asked more than nn queries, the program will print −1−1 and will finish interaction. You will receive a Wrong answer verdict. Make sure to exit immediately to avoid getting other verdicts. When you determine mm, output !! mm After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use: Hack format For the hacks use the following format: The first line has to contain three integers n,k,mn,k,m (1≤m≤k In the next line output nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109) — the elements of the array. They have to be pairwise different. Example input Copy output Copy E. Divide Points time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a set of n≥2n≥2 pairwise different points with integer coordinates. Your task is to partition these points into two nonempty groups AA and BB, such that the following condition holds: For every two points PP and QQ, write the Euclidean distance between them on the blackboard: if they belong to the same group — with a yellow pen, and if they belong to different groups — with a blue pen. Then no yellow number is equal to any blue number. It is guaranteed that such a partition exists for any possible input. If there exist multiple partitions, you are allowed to output any of them. Input The first line contains one integer nn (2≤n≤103)(2≤n≤103) — the number of points. The ii-th of the next nn lines contains two integers xixi and yiyi (−106≤xi,yi≤106−106≤xi,yi≤106) — the coordinates of the ii-th point. It is guaranteed that all nn points are pairwise different. Output In the first line, output aa (1≤a≤n−11≤a≤n−1) — the number of points in a group AA. In the second line, output aa integers — the indexes of points that you include into group AA. If there are multiple answers, print any. Examples input Copy output Copy input Copy output Copy input Copy output Copy input Copy output Copy input Copy output Copy 找一个点当成(0,0),然后所有坐标/2除到有奇数为止,然后坐标和奇数的一边,偶数的一边,如果坐标和全都是偶数,那么所有点的x和y奇偶性相同且有奇有偶,那就按坐标奇偶性分成两边
4 3
4 9
4 9
4 9
1 2
? 2 3 4
? 1 3 4
? 1 2 4
? 1 2 3
#include
3
0 0
0 1
1 0
1
1
4
0 1
0 -1
1 0
-1 0
2
1 2
3
-2 1
1 1
-1 0
1
2
6
2 5
0 3
-4 -1
-5 -4
1 0
3 -1
1
6
2
-1000000 -1000000
1000000 1000000
1
1
#include