12.29
CF GoodBye 2019
Last year's race on purple, thank invincible cyy!
A.Card Game
Meaning of the questions: There are a total of 1-n n cards, two people start to take each random number every time the one, who will come to take away two big points, who should not lose cards, ask who won.
Thinking: has the largest that card wins.
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mid ((l+r)>>1)
const int M=1e5+20,P=1e9+7;
struct Task{
int n,k1,k2;
void init(){
scanf("%d%d%d",&n,&k1,&k2);
int mx1=0,mx2=0;
for(int i=1;i<=k1;++i){
int c;
scanf("%d",&c);
mx1=max(mx1,c);
}
for(int i=1;i<=k2;++i){
int c;
scanf("%d",&c);
mx2=max(mx2,c);
}
if (mx1>mx2)
printf("YES\n");
else
printf("NO\n");
}
void run(){
init();
}
}t;
int main(){
int T;
scanf("%d",&T);
for(int i=1;i<=T;++i)
t.run();
return 0;
}
B.Interesting Subarray
Meaning of the questions: if a array satisfy max (a) -min (a) > = the number of array elements, then call this array is interesting now to ask a given array, if there is a non-empty string array.
Ideas: It is conceivable that if the difference between two adjacent> = 2, then this is interesting in two. If all the difference between two adjacent are <= 1, then the whole does not exist in the interesting sub-array.
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mid ((l+r)>>1)
const int M=2e5+20,P=1e9+7;
struct Task{
int n,a[M];
void init(){
scanf("%d",&n);
for(int i=1;i<=n;++i)
scanf("%d",&a[i]);
}
void run(){
init();
for(int i=2;i<=n;++i)
if (abs(a[i]-a[i-1])>=2){
printf("YES\n%d %d\n",i-1,i);
return ;
}
printf("NO\n");
}
}t;
int main(){
int T;
scanf("%d",&T);
for(int i=1;i<=T;++i)
t.run();
return 0;
}
C.Make Good
Meaning of the questions: If the number of string and = XOR and twice, then this is a good bunch of numbers. It is required to increase the number of no more than 3, so that it becomes a good.
Thinking: This question is very simple idea in mind and is ...... s, XOR and is xs, then the first plus xs, becomes s + xs, 0, then add s + xs, can be.
My idea is to first form into an s 100,000,000, while ensuring the exclusive OR of bits and the number of bits = s -1, corresponding to those in s after the XOR and further into an inside of a can 1, In fact, very complicated.
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mid ((l+r)>>1)
#define db(x) cout<<#x<<":"<<x<<endl;
const int M=2e5+20,P=1e9+7;
struct Task{
int n;
LL sump=0,sumx=0;
void init(){
scanf("%d",&n);
sump=sumx=0;
for(int i=1;i<=n;++i){
int c;
scanf("%d",&c);
sump+=c,sumx^=c;
}
}
int get_max(LL a){
int p=0;
while(a>=(1LL<<p))
++p;
return p;
}
void run(){
init();
if (sump==0){
printf("0\n\n");
return;
}
LL o1=0,o2=0;
int ca1=get_max(sump),ca2=get_max(sumx);
o1=(1LL<<ca1)-sump;
sump+=o1,sumx^=o1;
ca1=get_max(sump),ca2=get_max(sumx);
if (ca1==ca2)
o1+=(1LL<<ca1)+(1LL<<(ca1-1)),sump+=(1LL<<ca1)+(1LL<<(ca1-1)),sumx^=((1LL<<ca1)+(1LL<<(ca1-1))),ca1+=2;
else if (ca1>ca2+1)
o1+=(1LL<<(ca1-1)),sump+=(1LL<<(ca1-1)),sumx^=(1LL<<(ca1-1)),ca1+=1;
printf("3\n");
printf("%lld ",o1);
for(int i=ca1-2;i>=2;--i)
if ((sumx>>(i-1))&1)
o2+=(1LL<<(i-1));
printf("%lld %lld\n",o2,o2);
}
}t;
int main(){
int T;
scanf("%d",&T);
for(int i=1;i<=T;++i)
t.run();
return 0;
}
D.Strange Device
The meaning of problems: there is a strange machine, for a sequence of n number (not the same number), each time you enter the k different positions, it returns the number of positions on the k first large m. Now requires asked not exceeding n times, find the value of m.
Ideas: This title is quite silly. The sample has hinted practices. Consider only k + 1 number, the number of all the mask sequence, the answer must be a large number m and k + 1-m small number.
For example, 12345678, m = 5, then the output is: 66666555. If m = 3, then the result is 44433333.
Find the law, right?
#include<bits/stdc++.h>
using namespace std;
map<int,int> mp;
int main(){
int n,k;
scanf("%d%d",&n,&k);
for(int i=1;i<=k+1;++i){
printf("?");
for(int j=1;j<=k+1;++j)
if (j!=i)
printf(" %d",j);
putchar('\n');
cout.flush();
int s1,s2;
cin>>s1>>s2;
++mp[s2];
}
map<int,int>::iterator it=mp.begin();
int val1=it->first,num1=it->second;
++it;
int val2=it->first;
if (val1<val2)
printf("! %d\n",it->second);
else
printf("! %d\n",num1);
cout.flush();
return 0;
}
E.Divide Points
The meaning of problems: there are n different points, divided into A and B requires two sets, so that the distance between the inner set of set points, the distance between the pair set with no intersection between the set of points.
Ideas: CYY taught me ...... first consideration since it is dyed black and white, then the parity think of x + y. Indeed, the division of x + y is an odd number to A, x + y is an even number can be classified into the B. Such a collection of interior points of (sum of squared differences) must be an even number, and the distance between the set of points must be odd, thus ensuring a certain distance after the roots are not the same distance apart. Next, consider x + y is a whole odd or all even. In fact to the rotating coordinate system, conversion is similar to the cut Chebyshev distance and Manhattan distance. See code.
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mid ((l+r)>>1)
const int M=1e3+20,P=1e9+7;
struct Point{
int x,y;
Point(int a=0,int b=0):x(a),y(b){}
};
struct Task{
int n;
Point a[M];
void init(){
scanf("%d",&n);
for(int i=1;i<=n;++i)
scanf("%d%d",&a[i].x,&a[i].y);
}
void run(){
init();
while(1){
int ou=0,ji=0;
for(int i=1;i<=n;++i)
if ((a[i].x+a[i].y)%2==0)
++ou;
else
++ji;
if (ou!=n&&ou!=0){
printf("%d\n",ou);
bool kong=false;
for(int i=1;i<=n;++i){
if (kong)
putchar(' ');
if ((a[i].x+a[i].y)%2==0)
printf("%d",i),kong=true;
}
putchar('\n');
return;
}
else{
if (ji==n)
for(int i=1;i<=n;++i)
a[i].y+=1;
for(int i=1;i<=n;++i){
int cax=a[i].x,cay=a[i].y;
a[i].x=(cax+cay)/2,a[i].y=(cax-cay)/2;
}
}
}
}
}t;
int main(){
t.run();
return 0;
}