仅A,B,C,D四题
A. Collecting Coins
Polycarp has three sisters: Alice, Barbara, and Cerene. They’re collecting coins. Currently, Alice has aa coins, Barbara has bb coins and Cerene has cc coins. Recently Polycarp has returned from the trip around the world and brought nn coins.
He wants to distribute all these nn coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives AA coins to Alice, BB coins to Barbara and CC coins to Cerene (A+B+C=nA+B+C=n), then a+A=b+B=c+Ca+A=b+B=c+C.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all nn coins between sisters in a way described above.
You have to answer tt independent test cases.
Input
The first line of the input contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases.
The next tt lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a,b,ca,b,c and nn (1≤a,b,c,n≤1081≤a,b,c,n≤108) — the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
Output
For each test case, print “YES” if Polycarp can distribute all nn coins between his sisters and “NO” otherwise.
Example
inputCopy
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
outputCopy
YES
YES
NO
NO
YES
水题直接上代码(可以改进但我表示懒得改)
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
int n,z,sum=0;
int x,y,s;
cin>>n;
while(n--){
cin>>x>>y>>z>>s;
if(x>=y&&x>=z){
sum=s-(x-y+x-z);
if(sum>=0&&sum%3==0){
cout<<"YES\n";
}
else{
cout<<"NO\n";
}
}
else if(y>=x&&y>=z){
sum=s-(y-x+y-z);
if(sum>=0&&sum%3==0){
cout<<"YES\n";
}
else{
cout<<"NO\n";
}
}
else if(z>=y&&z>=x){
sum=s-(z-x+z-y);
if(sum>=0&&sum%3==0){
cout<<"YES\n";
}
else{
cout<<"NO\n";
}
}
}
}
B. Collecting Packages
There is a robot in a warehouse and nn packages he wants to collect. The warehouse can be represented as a coordinate grid. Initially, the robot stays at the point (0,0)(0,0). The ii-th package is at the point (xi,yi)(xi,yi). It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point (0,0)(0,0) doesn’t contain a package.
The robot is semi-broken and only can move up (‘U’) and right (‘R’). In other words, in one move the robot can go from the point (x,y)(x,y) to the point (x+1,yx+1,y) or to the point (x,y+1)(x,y+1).
As we say above, the robot wants to collect all nn packages (in arbitrary order). He wants to do it with the minimum possible number of moves. If there are several possible traversals, the robot wants to choose the lexicographically smallest path.
The string ss of length nn is lexicographically less than the string tt of length nn if there is some index 1≤j≤n1≤j≤n that for all ii from 11 to j−1j−1 si=tisi=ti and sj Input The first line of a test case contains one integer nn (1≤n≤10001≤n≤1000) — the number of packages. The next nn lines contain descriptions of packages. The ii-th package is given as two integers xixi and yiyi (0≤xi,yi≤10000≤xi,yi≤1000) — the xx-coordinate of the package and the yy-coordinate of the package. It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point (0,0)(0,0) doesn’t contain a package. The sum of all values nn over test cases in the test doesn’t exceed 10001000. Output If it is impossible to collect all nn packages in some order starting from (0,00,0), print “NO” on the first line. Otherwise, print “YES” in the first line. Then print the shortest path — a string consisting of characters ‘R’ and ‘U’. Among all such paths choose the lexicographically smallest path. Note that in this problem “YES” and “NO” can be only uppercase words, i.e. “Yes”, “no” and “YeS” are not acceptable. Example C. Product of Three Numbers If there are several answers, you can print any. You have to answer tt independent test cases. Input The next nn lines describe test cases. The ii-th test case is given on a new line as one integer nn (2≤n≤1092≤n≤109). Output Otherwise, print “YES” and any possible such representation. Example D. MEX maximizing for the array [0,0,1,0,2][0,0,1,0,2] MEX equals to 33 because numbers 0,10,1 and 22 are presented in the array and 33 is the minimum non-negative integer not presented in the array; You are also given qq queries. The jj-th query consists of one integer yjyj and means that you have to append one element yjyj to the array. The array length increases by 11 after a query. In one move, you can choose any index ii and set ai:=ai+xai:=ai+x or ai:=ai−xai:=ai−x (i.e. increase or decrease any element of the array by xx). The only restriction is that aiai cannot become negative. Since initially the array is empty, you can perform moves only after the first query. You have to maximize the MEX (minimum excluded) of the array if you can perform any number of such operations (you can even perform the operation multiple times with one element). You have to find the answer after each of qq queries (i.e. the jj-th answer corresponds to the array of length jj). Operations are discarded before each query. I.e. the array aa after the jj-th query equals to [y1,y2,…,yj][y1,y2,…,yj]. Input The next qq lines describe queries. The jj-th query consists of one integer yjyj (0≤yj≤1090≤yj≤109) and means that you have to append one element yjyj to the array. Output Examples After the first query, the array is a=[0]a=[0]: you don’t need to perform any operations, maximum possible MEX is 11.
The first line of the input contains an integer tt (1≤t≤1001≤t≤100) — the number of test cases. Then test cases follow.
Print the answer for each test case.
inputCopy
3
5
1 3
1 2
3 3
5 5
4 3
2
1 0
0 1
1
4 3
outputCopy
YES
RUUURRRRUU
NO
YES
RRRRUUU
Note
For the first test case in the example the optimal path RUUURRRRUU is shown below:
水题直接上代码(可以改进但我表示懒得改)#include
You are given one integer number nn. Find three distinct integers a,b,ca,b,c such that 2≤a,b,c2≤a,b,c and a⋅b⋅c=na⋅b⋅c=n or say that it is impossible to do it.
The first line of the input contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases.
For each test case, print the answer on it. Print “NO” if it is impossible to represent nn as a⋅b⋅ca⋅b⋅c for some distinct integers a,b,ca,b,c such that 2≤a,b,c2≤a,b,c.
inputCopy
5
64
32
97
2
12345
outputCopy
YES
2 4 8
NO
NO
NO
YES
3 5 823
水题直接上代码(可以改进但我表示懒得改)#include
Recall that MEX of an array is a minimum non-negative integer that does not belong to the array. Examples:
for the array [1,2,3,4][1,2,3,4] MEX equals to 00 because 00 is the minimum non-negative integer not presented in the array;
for the array [0,1,4,3][0,1,4,3] MEX equals to 22 because 22 is the minimum non-negative integer not presented in the array.
You are given an empty array a=[]a=[] (in other words, a zero-length array). You are also given a positive integer xx.
The first line of the input contains two integers q,xq,x (1≤q,x≤4⋅1051≤q,x≤4⋅105) — the number of queries and the value of xx.
Print the answer to the initial problem after each query — for the query jj print the maximum value of MEX after first jj queries. Note that queries are dependent (the array changes after each query) but operations are independent between queries.
inputCopy
7 3
0
1
2
2
0
0
10
outputCopy
1
2
3
3
4
4
7
inputCopy
4 3
1
2
1
2
outputCopy
0
0
0
0
Note
In the first example:
After the second query, the array is a=[0,1]a=[0,1]: you don’t need to perform any operations, maximum possible MEX is 22.
After the third query, the array is a=[0,1,2]a=[0,1,2]: you don’t need to perform any operations, maximum possible MEX is 33.
After the fourth query, the array is a=[0,1,2,2]a=[0,1,2,2]: you don’t need to perform any operations, maximum possible MEX is 33 (you can’t make it greater with operations).
After the fifth query, the array is a=[0,1,2,2,0]a=[0,1,2,2,0]: you can perform a[4]:=a[4]+3=3a[4]:=a[4]+3=3. The array changes to be a=[0,1,2,2,3]a=[0,1,2,2,3]. Now MEX is maximum possible and equals to 44.
After the sixth query, the array is a=[0,1,2,2,0,0]a=[0,1,2,2,0,0]: you can perform a[4]:=a[4]+3=0+3=3a[4]:=a[4]+3=0+3=3. The array changes to be a=[0,1,2,2,3,0]a=[0,1,2,2,3,0]. Now MEX is maximum possible and equals to 44.
After the seventh query, the array is a=[0,1,2,2,0,0,10]a=[0,1,2,2,0,0,10]. You can perform the following operations:
a[3]:=a[3]+3=2+3=5a[3]:=a[3]+3=2+3=5,
a[4]:=a[4]+3=0+3=3a[4]:=a[4]+3=0+3=3,
a[5]:=a[5]+3=0+3=3a[5]:=a[5]+3=0+3=3,
a[5]:=a[5]+3=3+3=6a[5]:=a[5]+3=3+3=6,
a[6]:=a[6]−3=10−3=7a[6]:=a[6]−3=10−3=7,
a[6]:=a[6]−3=7−3=4a[6]:=a[6]−3=7−3=4.
The resulting array will be a=[0,1,2,5,3,6,4]a=[0,1,2,5,3,6,4]. Now MEX is maximum possible and equals to 77.
水题(可以改进但我表示懒得改)
题意:
q次询问,每次放进一个数(开始为空数组),可以对数组内的某个数或者某几个数做任意操作数的加x或者减x (x为input第二个数),处理完后询问,在该数组情况下的最小整数,就是数组里的数都被排除的情况下,从0开始找,第一个不在数组里的整数就是了,然后要求操作加x或者减x的任意操作后使得那个询问结果最大化。
思路:水题啊!!!明显是要让他尽可能覆盖从0开始的整数,把小的整数盖掉才会得到大的结果,如果小的那个比如说1,已经被覆盖,然后给你一个数它是1+nx,毫无疑问这个数%x得1,然后从1开始找,1已经有了,就1+1x覆盖,以此类推就行了!本题问题主要是方法乱容易超时,数据大容易runtime error。#include