CF 706D

Very typical CF question, the amount of code is not large, but the details are very tight, and the question is easy to read wrong

Ideas (discussion by category):

Seeing one going down and one going up, as far as possible —> think of the longest monotonous sub-column

Discuss based on the length of monotonic sub-columns:

1. If A chooses a point on the non-longest column, then B can choose the lowest point on the longest column, and A will lose

2. Select one point on the longest column of A,

{1} A chooses the point in the middle of the longest column, B is directly below, A must lose

{2}A choose the highest point of the longest column

(1) B chooses another longest column, A will lose

(2) The number of longest columns is unique, and B and A select the same longest column.

      [1] A and B walk opposite each other, depending on the path parity

      [2] A and B go in the same direction, provided that B knows that going against A will lose. It depends on the length of the other column connected to the highest point of the longest column.

Since the boundary is not cyclic (1 cannot go to n), it is necessary to judge the boundary specially

1. If A wants to select the sequence of the boundary, B can be directly selected and blocked at the bottom, and A will fail -> A cannot choose the column of the boundary (throw away the other end point outside the boundary)

{1} If the boundary column is the longest column, B can be selected at the lowest point, and A will fail

{2} If the boundary column is not the longest column, B will not be selected.

 

The following needs to be merged according to the conditions to facilitate writing code

In summary,

1. If the boundary is the longest column, A will lose.

2. A can only choose the highest point of the longest column.

{1} Find the highest number of points, if the number is not unique, A will lose

{2} If it is unique, determine the parity and the length of the other column, and discuss the failure of A.

 

Note: The number of longest columns does not correspond to the number of highest points. Such as /\ shape, two longest columns, but only one highest point,

 

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll k,n,m,x,y,ans,ans2,lin,a[100005];
double ansf,b[100005];
bool up; 
int i,j,l,r,T,mk; 
char ch[150];
void cmpupdate(int sx)
{
    if(a[i]>a[i-1])
{
        if(up)lin++;
     else lin=1;
    up=1; 
}else
{
    if(!up)lin++;
     else lin=1;
    up=0; 
}
if(sx==1){if(lin>ans){ans=lin;}}
    if(sx==2)
    {
    if(lin==ans)
    {
    ans2++;
    if(up){while(i<n&&a[i+1]<a[i])i++;up=0;    }
    
    }    
    }
    if(sx==3)
    {
        if(lin==ans)
    {mk=i;
if(up){
while(i<n&&a[i+1]<a[i])i++;
mk=i-mk; 
}    else
{
while(i>1&&a[i-1]<a[i])i--;
mk=mk-i;     
}
        i=n;
}
    }
}
int main()
{
scanf("%lld",&n);
scanf("%lld",&a[1]);
scanf("%lld",&a[2]);
i=2;
lin=up=0;
cmpupdate(1);
ans=1;
for(i=3;i<=n;i++)
{
scanf("%lld",&a[i]);
cmpupdate(1);

lin=up=0;
for(i=2;i<=n;i++)
{
cmpupdate(2);

i=2;
while(a[i]<a[i-1]&&i<=n)i++;
if(i-2==ans)ans2=0;
i=n;
while(a[i]>a[i-1]&&i>=1)i--;
if(n-i-1==ans)ans2=0;
if(ans2==0||ans2>1){
printf("0");
return 0;
}
if(ans%2==1)printf("0");
else {
for(i=2;i<=n;i++)
{
    cmpupdate(3);
}
ans--;
if(ans>=mk)printf("0");else
printf("1");    
}
}
 

 

 

 

Guess you like

Origin blog.csdn.net/haobang866/article/details/114684539