Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
水人做水体 代码也很挫 哎#include <iostream> using namespace std; int main() { int n; int len[4]={0}; int a[30002]; cin>>n; int i=0; int ans1,ans2; while(i<n) { cin>>a[i++]; } len[a[0]]++; for(i = 1;i < n;i++) { if(a[i]==3) len[a[i]]++; else if(a[i]==2) { if(len[3]==0) len[2]++; else { len[3]--; len[2]++; } } else { if(len[2]+len[3]==0) len[1]++; else { if(len[2]!=0) { len[2]--; len[1]++; } else { len[3]--; len[1]++; } } } } ans1= len[1]+len[2]+len[3]; i = 0; while(i<n) { a[i]=4-a[i]; i++; } len[1]=0; len[2]=0; len[3]=0; len[a[0]]++; for(i = 1;i < n;i++) { if(a[i]==3) len[a[i]]++; else if(a[i]==2) { if(len[3]==0) len[2]++; else { len[3]--; len[2]++; } } else { if(len[2]+len[3]==0) len[1]++; else { if(len[2]!=0) { len[2]--; len[1]++; } else { len[3]--; len[1]++; } } } } ans2= len[1]+len[2]+len[3]; if(ans1>ans2) cout<<n-ans1<<endl; else cout<<n-ans2<<endl; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator