2019 summer school third off more cattle

B题:Crazy Binary String

 

The longest 01 B title sequence that is quite clear

We take in a minimum of two times the number of 0,1, so, this is clearly the best or well done

 

But we are, then we how to operate on the 01 string balance it?

Is a very naive idea what the nature of this series it: the same number of 0 to 1, 01 to cancel each other, for as long as two corresponding odd bits and even bits in the middle of two corresponding 01 can eliminate the words of each other

So we can calculate the contribution of this, then it just makes trouble on ok

 

There is also a bell idea is half the length, and then check, this is a problem such as this, then 8 11000011 can be, is not enough 4   

Young how about this example made it, I do not know ah? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

This also lacks recourse but to rely on their own understanding of the   

Here is the code:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #include <iostream>
 5 #include <cmath>
 6 #include <bitset>
 7 typedef long long ll;
 8 using namespace std;
 9 const int maxn=(int)(1e5+2000);
10 int n;
11 char s[maxn];
12 int qilen[maxn*2],oulen[maxn*2];
13 int main(){
14     scanf("%d",&n);
15     scanf("%s",s+1);
16     memset(qilen,-1,sizeof(qilen));
17     memset(oulen,-1,sizeof(oulen));
18     int cnt0=0,cnt1=0;
19     int ans=0;
20     oulen[maxn]=0;
21     int q=maxn;
22     //cout<<q<<endl;
23     for(int i=1;i<=n;i++){
24         if(s[i]=='0') cnt0++;
25         else cnt1++;
26         if(s[i]=='0') q--;
27         else q++;
28        // cout<<q<<endl;
29         if(i%2==1){
30             if(qilen[q]==-1) qilen[q]=i;
31             else{
32                  years = max (years (i qilen [q]));
33              }
 34          } else {
 35              if (Oulen [q] == - 1 ) Oulen [q] = i;
36              Else years = max (years i Oulen [q]);
37          }
 38      }
 39      printf ( " % d% d \ n " , year 2 * min (CNT0, CNT1));
40      return  0 ;
41 }
View Code

 

H题:Magic Line

After this question, then we must first think about how to divide into two halves, one of the most simple idea is sort of drained order   

Because it is an even number, the midpoint naturally arises

Then intermediate points separate them, particularly with a two 1E9, -1e9 to separate points on ok, this is still very good operation. Probably all of a sudden be able to get rid of

Here is the code:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #include <iostream>
 5 #include <cmath>
 6 #include <bitset>
 7 typedef long long ll;
 8 using namespace std;
 9 const int maxn=1100;
10 const ll Max=(ll)(1e9);
11 int t,n;
12 struct point{
13     ll xi,yi;
14 };
15 point sum[maxn];
16 
17 bool cmp(point p1,point p2){
18     if(p1.xi==p2.xi) return p1.yi<p2.yi;
19     else return p1.xi<p2.xi;
20 }
21 
22 int main(){
23     scanf("%d",&t);
24     while(t--){
25         scanf("%d",&n);
26         for(int i=1;i<=n;i++) scanf("%lld%lld",&sum[i].xi,&sum[i].yi);
27         sort(sum+1,sum+n+1,cmp);
28         int m=n/2;
29         if(sum[m].xi==sum[m+1].xi){
30             if((sum[m+1].yi-sum[m].yi)%2==1){
31                 printf("%lld %lld %lld %lld\n",sum[m].xi-1,(ll)(3e8)+sum[m+1].yi,sum[m].xi+1,sum[m].yi-(ll)(3e8));
32             }else{
33                 ll y=(sum[m+1].yi+sum[m].yi)/2;
34                 printf("%lld %lld %lld %lld\n",sum[m].xi-1,(ll)(3e8)+y,sum[m].xi+1,y-(ll)(3e8));
35             }
36         }else{
37             ll y=(sum[m].yi+sum[m+1].yi)/2;
38             printf("%lld %lld %lld %lld\n",sum[m].xi,y+(ll)(3e8),sum[m+1].xi,y-(ll)(3e8));
39         }
40     }
41     return 0;
42 }
View Code

 

 

F题:Planting Trees

This, then how do we do it? ? ? ? ?

First, we know that if we want to get the maximum range, according to his data, know that this situation is something that needs exhaustive, this word is up to us to try to find.

I think every track is a road simulation acm title question, he will give you a condition, then we under these conditions, the application up and found a property with one of these applications up things, and finally

Depending on the nature of the approach we have come to this topic, this is the general practice of Acm question

    

Guess you like

Origin www.cnblogs.com/pandaking/p/12112464.html