A.BowWow and the Timetable
• the meaning of problems
The number gives you a binary number, so that you find less than the number of all the powers of 4
• ideas
The first reaction is binary and quaternary conversion
(In fact, no real conversion QwQ)
Due to the corresponding binary two of a quaternary
So we can get the number of bits in a quaternary
Quaternary equal to the number of bits is less than the power of all of the number 4, the analog power decimal 10
Because there are not equal, it is based on the binary determine what this number is not a power of 4
Because 1 2 100 2 10000 2 , 4 in addition to the binary power of a first, followed by an even number 0
It is determined whether an even number with 0, if the number is one less
• Code
View Code1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn=1e6+5; 4 char s[maxn]; 5 int main() 6 { 7 scanf("%s",s+1); 8 int len=strlen(s+1),flag=0; 9 int cnt=(len+1)/2; 10 for(int i=2;i<=len;i++) 11 if(s[i]=='0') flag++; 12 if(flag==len-1 && len&1) 13 cnt--; 14 printf("%d\n",cnt); 15 }
B.Mislove Has Lost an Array
• the meaning of problems
Array there is only $ 1 or $ X $ $
$ X $ is even and $ x / 2 $ must exist in the array
Given $ l, r $ array least $ L $ different numbers, up to $ $ R & lt different numbers
The minimum and maximum number of array seek
• ideas
There is a minimum of $ 1, 2,4 ... L $ $ $ like number, if the number n is less than $ 1 $ filled with
There is a maximum of $ 2, 4 and so on ... $ $ r $ the number, if it is less than $ r $ with the largest number of filled
• Code
View Code1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 int main() 5 { 6 int n,l,r; 7 cin>>n>>l>>r; 8 ll Min=0; 9 int cnt,i; 10 for(i=1,cnt=1;i<=l;cnt*=2,i++) 11 Min+=cnt; 12 Min+=(n-l); 13 14 ll Max=0; 15 for(cnt=1,i=1;i<=min(n,r);cnt*=2,i++) 16 Max+=cnt; 17 cnt/=2; 18 if(r<=n) 19 Max+=1ll*(n-r)*cnt; 20 cout<<Min<<' '<<Max<<endl; 21 }
D.Kirk and a Binary String
• the meaning of problems
Give you a $ 01 $ string s, t let you find a string, so that
- interval t s string and string the same length all monotone nondecreasing
- t 0 up to the number of strings
• ideas
For a string, the current position of the two cases have $ 0 $
- The current position is 0
The current position is 0, for he was the starting point of a non-monotonically decreasing sequences certainly contribute,
If the length of the lower becomes 1, it will decrease in most cases (except where all the back 0 1 011 111 the same length)
If the number of changes to reduce the ratio of 1,0 unchanged contrary to the second task
- The current position is 1
If the value of 0, for his (it is 1) as a starting point monotonically non-decreasing sequence, the length has no effect
For at zero monotonically non-decreasing sequence, the length will be affected
Since want more of 0, it would need as much as possible to 1 to a 0, then how can it have no effect?
He would need to length (it is 1) as a starting point monotonically non-decreasing sequences of greater than at zero monotonically non-decreasing sequence length
Because that affect the overall situation of the longest, let even small changes, and nor will the overall impact!
In other words, if you want to become $ $ $ 0 $ 1, we must ensure that all monotonic non-decreasing interval behind the sub-sequence length must equal the number 1
I.e. looking from the rear forward, when the number is greater than the number of $ 1 $ $ $ 0 and $ 1 can become $ $ $ 0
• Code
View Code1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 const int maxn=1e6+4; 5 char s[maxn]; 6 int a[maxn]; 7 int main() 8 { 9 scanf("%s",s+1); 10 int len=strlen(s+1); 11 int cnt=0; 12 for(int i=len;i>=1;i--) 13 { 14 if(s[i]=='0') 15 cnt++; 16 else 17 { 18 if(cnt) --cnt; 19 else s[i]='0'; 20 } 21 } 22 23 printf("%s",s+1); 24 }