Garland-cf

  The meaning of problems: a sequence number is missing some length of n 1 to n element is not re-sample, the number of the required deletion and filling into two as far as possible the number of adjacent same parity, the parity output of the minimum adjacent the number of the number of different.

 

  Thinking: Maintenance is also an odd number and even number can be filled, if odd odd 0 ... 0 , resembling this range, which can be filled if the number of the same nature, and then filled, filling in on priority, then the number - length and then consider the range of different properties, similar to the odd .... 0 0 even this minimal contribution to the range of answers is 1, and will be able to be 1, then is to determine the extreme left and the extreme right, if enough filled to the next , to answer no contribution, not fit so much contribution is 1.

 

 

Record about my autistic trip!

 

 AC code is only :( I can understand, manual funny!)

 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 
 5 int n;
 6 int a[160],vis[3];
 7 int k,cnt;
 8 
 9 struct node2{
10     int len;
11     int col;
12 }n2[160];
13 
14 struct node1{
15     int col,pos;
16 }n1[160];
17 
18 bool cmp(node2 a,node2 b){
19     return a.len<b.len;
20 }
21 
22 void checkn1(){
23     for(int i=1;i<=k;i++){
24         cout<<i<<"->"<<n1[i].col<<" "<<n1[i].pos<<endl;
25     }
26 }
27 
28 void checkn2(){
29     cout<<"checkn2\n";
30     for(int i=1;i<=cnt;i++){
31         cout<<i<<"->"<<n2[i].col<<" "<<n2[i].len<<endl;
32     }
33 }
34 
35 int main()
36 {
37     cin>>n;
38 
39     for(int i=1;i<=n;i++){
40         cin>>a[i];
41         if(a[i]!=0){
42             n1[++k].col=a[i]%2;
43             n1[k].pos=i;
44             vis[a[i]%2]++;
45         }
46     }
47     if(n==1){
48         cout<<0;
49         return 0;
50     }
51     //
52     //checkn1();
53     int ans=0;
54     for(int i=1;i<=k-1;i++){
55         if(n1[i].col==n1[i+1].col&& n1[i+1].pos-n1[i].pos-1!=0 ){
56             n2[++cnt].col=n1[i].col;
57             n2[cnt].len=n1[i+1].pos-n1[i].pos-1;
58         }
59         if(n1[i].col!=n1[i+1].col) ans++;
60     }
61     //checkn2();
62     sort(n2+1,n2+1+cnt,cmp);
63     int os=n/2-vis[0],js=(n+1)/2-vis[1];
64     for(int i=1;i<=cnt;i++){
65         node2 now=n2[i];
66         if(now.col==1){
67             if(now.len<=js)
68                 js-=now.len;
69             else
70                 ans+=2;
71         }
72         else if(now.col==0){
73             if(now.len<=os)
74                 os-=now.len;
75             else
76                 ans+=2;
77         }
78     }
79 //    cout<<"caonima2 "<<ans<<endl;
80     int tmp;
81 
82     if(a[1]==0&&n1[1].col==1&&js<n1[1].pos-1) ans++;
83     if(a[n]==0&&n1[k].col==1&&js<n-n1[k].pos) ans++;
84 
85     if(a[1]==0&&n1[1].col==0&&os<n1[1].pos-1) ans++;
86     if(a[n]==0&&n1[k].col==0&&os<n-n1[k].pos) ans++;
87 
88     if(k==0||k==1) ans=1;
89     cout<<ans;
90     return 0;
91 }
View Code

Guess you like

Origin www.cnblogs.com/qq2210446939/p/12158484.html