训练做到了去年校内省选题
唉 当时就剩10分钟这道题做不完了
现在再写几分钟就写完了
希望今年的沈阳顺利吧
(安稳退役?
1 #include<bits/stdc++.h> 2 #define cl(a,b) memset(a,b,sizeof(a)) 3 #define debug(a) cerr<<#a<<"=="<<a<<endl 4 using namespace std; 5 typedef long long ll; 6 typedef pair<int,int> pii; 7 8 const int maxn=1e5+10; 9 10 bool solve(vector<int> b,vector<int> tmp,int &ans) 11 { 12 for(int i=0; i<b.size(); i++) 13 { 14 if(b[i]!=tmp[i]) 15 { 16 int loc=0; 17 for(int j=i+1; j<tmp.size(); j++) 18 { 19 if(b[j]!=tmp[j]&&b[i]!=b[j]) 20 { 21 loc=j; 22 break; 23 } 24 } 25 ans+=(loc-i); 26 swap(b[i],b[loc]); 27 } 28 } 29 // debug(ans); 30 if(b==tmp) return true; 31 else return false; 32 } 33 34 void change(vector<int> p,vector<int> &tmp,int now) 35 { 36 for(auto i:p) 37 { 38 int t=i; 39 while(t--) tmp.push_back(now); 40 if(now==1) now=0; 41 else now=1; 42 } 43 // for(auto i:tmp) 44 // { 45 // printf("%d ",i); 46 // } 47 // printf(" "); 48 } 49 50 int main() 51 { 52 int n,m; 53 while(~scanf("%d%d",&n,&m)) 54 { 55 vector<int>b(n,0); 56 vector<int>p(m,0); 57 for(auto& i:b) 58 { 59 scanf("%d",&i); 60 } 61 for(auto& i:p) 62 { 63 scanf("%d",&i); 64 } 65 vector<int>tmp1,tmp2; 66 tmp1.clear(); 67 tmp2.clear(); 68 change(p,tmp1,1); 69 change(p,tmp2,0); 70 int ans=10000000,ans1=0,ans2=0; 71 if(solve(b,tmp1,ans1)) ans=min(ans,ans1); 72 if(solve(b,tmp2,ans2)) ans=min(ans,ans2); 73 printf("%d ",ans); 74 } 75 return 0; 76 }/* 77 78 6 3 79 1 0 0 1 0 1 80 1 3 2 81 7 2 82 1 1 1 0 0 0 0 83 4 3 84 15 14 85 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 86 1 1 1 1 1 1 1 1 1 1 1 1 1 2 87 1 1 88 0 89 1 90 91 */