Game link: http://codeforces.com/contest/1180
Problem A
Meaning of the questions: given n, the number of squares asked. Figure understood. . .
Solution:
Law can look for the found block number is 2n * (n-1) +1
Code:
#include<bits/stdc++.h>
using namespace std;
int read(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
int main(){
int n=read();
printf("%d\n",2*n*n-2*n+1);
return 0;
}
Problem B
Question is intended: to give you a sequence, where you can put it into any element opposite of -1, that: \ (a_i:--a_i. 1 \) , do the most program product
Solution:
Apparently as many non-negative number to perform this operation is optimal, and we are bound to make this the largest non-negative product
While for two non-negative \ (a, b (b> a) \) is, \ ((A +. 1) B> A (B +. 1) \)
So we only need to sequence the smallest negative value after the operation to perform and compare the size of the largest non-negative on the line
Code:
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;
int n,_minus,add,a[N];
int maxm,maxa=-1,idm,ida;
int read(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
int main(){
n=read();
for(int i=1;i<=n;i++){
a[i]=read();
a[i]>=0?++add:++_minus;
if(a[i]>=0&&a[i]>maxa) ida=i,maxa=a[i];
if(a[i]<0&&a[i]<maxm) idm=i,maxm=a[i];
}int f1=_minus%2,f2=add%2;
if(f1==f2){
for(int i=1;i<=n;i++)
printf("%d ",a[i]<0?a[i]:-a[i]-1);
return 0;
}
if(_minus==1&&!add){
printf("%d ",-a[1]-1);
return 0;
}
if(f1!=f2){
int id,flag=0;
if(-maxm-1>maxa) id=idm;
else id=ida,flag=1;
for(int i=1;i<id;i++)
printf("%d ",a[i]<0?a[i]:-a[i]-1);
printf("%d ",flag?a[id]:-a[id]-1);
for(int i=id+1;i<=n;i++)
printf("%d ",a[i]<0?a[i]:-a[i]-1);
}
}
Problem C
Question is intended: to give you a sequence, each operation sequence before removing the two elements \ (A, B \) , the larger elements in the first sequence, the smaller elements at the end of the sequence, there are m times query, each query you x-th operation out of which two elements
Solution:
Obviously, when the largest element in the sequence as the first, all the elements will be compared with it the tail kicked, form a cycle, and the replacement element to the head of the queue up to the maximum required operations n-1, then we can simulate the largest element replacement to all operations prior to the first team, after the operation, it can (1) is calculated according to the cycle O
Code:
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define fir first
#define sec second
using namespace std;
const int N=1e5+1;
int n,m,maxn;
int head,cnt,tail,q[N*31];
pair<int,int> u[N];
ll read(){
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
int main(){
n=read(),m=read();
for(int i=1;i<=n;i++){
q[++tail]=read();
if(q[i]>maxn) maxn=q[i];
}head=1;
while(1){
int x=q[head],y=q[head+1];
u[++cnt]=mp(x,y);
if(x==maxn) break;
if(x>y) q[head+1]=q[head++],q[++tail]=y;
else ++head,q[++tail]=x;
}
for(int i=1;i<=m;i++){
ll x=read();
if(x<=cnt) printf("%d %d\n",u[x].fir,u[x].sec);
else printf("%d %d\n",maxn,q[head+1+(x-cnt)%(n-1)]);
}
return 0;
}
Problem D
The meaning of problems: Given a matrix of n * m, you start a (1,1); every movement, set point is your location (x, y), you can select any tuple (dx, dy) , moved to (x + dx, y + dy) points, but each selected tuple (dx, dy) can not be used before. Now ask whether there is a plan to make you just go through each point in time, if there is, according to the order reaches the output point, or output -1.
Solution:
This is a configuration problem. From the (1,1) and (n, m) of the counter-shape round two jumping points sequentially, easy to prove correctness, Refer to code (described as not very good)
Code:
#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
const int N=1e6+1;
int n,m,add1=1,add2=-1;
int nx,ny,mx,my,flag;
int read(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
void ins(int opt){
if(!opt){
printf("%d %d\n",nx,ny);
if(nx+add1>n||nx+add1<1) ++ny,add1=-add1;
else nx+=add1;
}else{
printf("%d %d\n",mx,my);
if(mx+add2<1||mx+add2>n) --my,add2=-add2;
else mx+=add2;
}
}
int main(){
n=read(),m=read();
nx=ny=1,mx=n,my=m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
ins(flag),flag^=1;
return 0;
}