标签:style os for ar c++ amp har mil
贪心
#include<bits/stdc++.h> using namespace std; int main() { long long n; char s[100020]; while(scanf("%I64d",&n)==1) { scanf("%s",s); int len=strlen(s); long long sum1=0,sum2=0,ans=0; for(int j=0;j<len;j++) { if(s[j]=='1') { if(sum1+sum2*2+1<=n) sum1++; else { if(sum2>0) { sum2--; sum1++; } } } else { if(sum1+sum2*2+2<=n) sum2++; } ans+=(sum1+sum2); } printf("%I64d\n",ans); } return 0; }
HNU 12848 Energy Tycoon (贪心),布布扣,bubuko.com
标签:style os for ar c++ amp har mil
原文地址:http://blog.csdn.net/nenuxlp/article/details/38259597