I haven't trained for a while, but I'm in a state of decline...

A pity cf...

A C+=

General idea:

First give you two numbers a,b, and a number n; You can perform any operation. Each operation includes two situations: a+=b, b+=a. Ask you how many operations you have done at least. You can find a number in a and B that is strictly greater than n.

Ideas:

First of all, you can find that the values of a and b can be interchanged without any influence. Then I will let b be the largest number of a and b.

And then I found that if you only do one operation, there are two situations

1 (a,a+b);

2 (b,a+b);

Obviously operation 2 is better, and then operation 2 is selected for each operation. The complexity is about log level.

code:

#include<bits/stdc++.h> using namespace std; const int N=1e3+15; typedef long long ll; int main() { ll t,b,a,n; cin>>t; while(t--) { ll cnt=0; cin>>a>>b>>n; if(a>b) swap(a,b); if(a>n) { cout<<"0"<<endl; continue; } if(a+b>n) { //cnt++; cout<<"1"<<endl; continue; } if(a+2*b>n) { //cnt++; cout<<"2"<<endl; continue; } while(1) { cnt+=2; ll c=a+2*b; a=a+b; b=c; if(a+b>n) { //cnt++; cout<<(1+cnt)<<endl; break;//continue; } if(a+2*b>n) { //cnt++; cout<<(2+cnt)<<endl; break;//continue; } } } return 0; }

B. Codeforces Subsequences

It's too bad. It's stuck here for a long time, because the preprocessing range is getting smaller. It seems that this happened last time, In the future, we should be more serious in writing questions, not just in the state of verifying ideas first, but in the beginning.

Title:

Give you a K, and you'll find a string in which at least k subsequences are codeforces.

Ideas:

codeforces: 1

There are two codeforces

There are four codeforces

There are 8 codes for success

...

There are (512 * 3 = 1536) ccooddeeffoorrccecesss.

...

This is the law.

code:

#include<bits/stdc++.h> using namespace std; const int N=1e2+15; typedef long long ll; ll f[N][N]; int main() { ll t,b,a,n,k; for(int i=1;i<=100;i++) { f[i][0]=1; for(int j=1;j<=100;j++) { f[i][j]=f[i][j-1]*i; } } char str[100]; str[1]='c'; str[2]='o'; str[3]='d'; str[4]='e'; str[5]='f'; str[6]='o'; str[7]='r'; str[8]='c'; str[9]='e'; str[10]='s'; cin>>k; if(k==1) { cout<<"codeforces"<<endl; return 0; } if(k<=2) { cout<<"codeforcess"<<endl; return 0; } if(k<=4) { cout<<"codeforceess"<<endl; return 0; } for(int i=1;i<=100;i++) { if(f[i][10]>k) { for(int j=10;j>=0;j--) { ll op=f[i-1][j]*f[i][10-j]; if(op>=k) { for(int l=1;l<=j;l++) { for(int r=1;r<=i-1;r++) cout<<str[l]; } for(int l=j+1;l<=10;l++) { for(int r=1;r<=i;r++) cout<<str[l]; } cout<<endl; return 0; } } } } return 0; }

C. Even Picture

C is also a very annoying problem. There are so many problems I don't like....

You have a picture with many squares. You can paint some squares black.

But when you paint, you have some requirements

1. All grey grids are arbitrarily reachable, that is, grey grids are connected.

2 the number of gray squares in each neighbor is even.

Then I'll give you a number n, N, which means the number of squares with gray squares on the top, bottom, left and right.

Let you construct this picture

Ideas:

First, play n=1,n=2,n=3. Please see the picture

Then the rule is like this, but I've implemented it for a long time, because now I don't like writing code very much... I feel it necessary to practice simulation...

code:

#include<bits/stdc++.h> using namespace std; const int N=1e6+15; typedef long long ll; ll p[N],vis[N],a[N]; int main() { ll k; cin>>k; ll op=k*3+2+10; cout<<op<<endl; cout<<"0 0"<<endl; cout<<"1 0"<<endl; cout<<"2 0"<<endl; cout<<"0 1"<<endl; cout<<"2 1"<<endl; cout<<"0 2"<<endl; cout<<(k+3)<<" "<<(k+1)<<endl; cout<<(k+3)<<" "<<(k+2)<<endl; cout<<(k+3)<<" "<<(k+3)<<endl; cout<<(k+2)<<" "<<(k+3)<<endl; cout<<(k+1)<<" "<<(k+3)<<endl; cout<<(k+1)<<" "<<(k+2)<<endl; for(int i=2;i<=k+1;i++) { cout<<(i-1)<<" "<<(i)<<endl; cout<<(i)<<" "<<(i)<<endl; cout<<(i+1)<<" "<<(i)<<endl; } return 0; }

D. AND, OR and square sum

Title:

I'll give you a number n, and a number n.

You can do it any number of times.

Each operation is to find two numbers x,y; let x = x | y, y = y & X;

Ask you what the sum of the squares of the largest of them you can get by choosing the best strategy to operate.

Ideas:

think first of

If x=1,y=1, there is no effect after one operation.

If x=0,y=0, there is no effect after one operation.

If x=1,y=0, there is no effect after one operation.

If x=0,y=1, then after one operation, x = becomes 1,y becomes 0.

It is then found that this is the same for all binary counterparts.

Then it comes to mind that this means that you can swap 0 and 1 at will in binary cases.

Then record the number of 1s in each bit of binary system, and the maximum number that can be constructed by greedy construction at present is enough.

code:

#include<bits/stdc++.h> using namespace std; const int N=1e6+15; typedef long long ll; ll p[N],vis[N],a[N]; int main() { ll n; p[0]=1; for(int i=1;i<=25;i++) { p[i]=p[i-1]*2; } cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; } for(int i=1;i<=n;i++) { ll x=a[i]; for(int j=0;j<=23;j++) { if(x&p[j]) vis[j]++; } } ll ans=0; for(int i=1;i<=n;i++) { ll x=0; for(int j=0;j<=23;j++) { if(vis[j]>0) { vis[j]--; x=x|p[j]; } } ans+=x*x; } cout<<ans<<endl; return 0; }

F. Lamps on a Circle

Write the first interactive question. Good idea, but there's something wrong with the format. In the future, we should not bother with each other.

Title:

At the beginning, there are n lights in a ring. You and imp take turns to play the game. Turn system operation, you first.

Every time it's your turn to operate, you can choose to end the game or continue playing.

If you continue to play, you will first choose a number of K, and then choose k lights to light them up, which has no effect on the original lights.

Then imp operation, he selects a number x, and starts from X, turns off k lights clockwise, which has no effect on the ones that are already turned off.

You want the maximum number of lights to be turned on and imp wants the maximum number of lights to be turned off.

imp is smart, so are you.

Then you go through several rounds and get the maximum number of lights that can be on. And then it's over.

Ideas:

Look at these first

N = 510100, two lights are allowed

n=71010100, three lights.

N = 131110111011100, 9 lights.

N = 15111011101101110, 8 lights.

Then it's clear that the final situation is like this. You find a number k, which lights K, turns off 1, lights K, turns off 1... Until the end of the verdict.

Then the code is OK, but I thought imp would make the best decision all the time, but I found that it is not, this is interactive, it needs to add a special judgment.

#include<bits/stdc++.h> using namespace std; const int N=1e3+15; typedef long long ll; int main() { ll n,d; cin>>n; if(n<=3){ cout<<"0"<<endl; return 0; } for(d=1;;d++) if(d*(d+1)>n) break; ll op=d+1,x=1; for(ll i=1;;i++){ if(op>=n) break; cout<<d<<" "; for(int j=1;j<=d-1;j++){ if(x+j-1<=n) cout<<(x+j-1)<<" "; else cout<<(x+j-1-n)<<" "; } ll lx=x+d-2; if(lx>op) cout<<(x-1)<<endl; else cout<<op<<endl; op++; if(op%d==0) op++; cin>>x; } cout<<"0"<<endl; return 0; }