1. 程式人生 > >Jamie and Binary Sequence (changed after round) - CodeForces 916B

Jamie and Binary Sequence (changed after round) - CodeForces 916B

con tdi chang ren second ack pan else tar

http://codeforces.com/problemset/problem/916/B

好尬啊。。。

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<vector>
 5 #include<map>
 6 using namespace std;
 7 #define fi first
 8 #define se second
 9 #define mp make_pair
10 #define pb push_back
11
typedef long long ll; 12 typedef unsigned long long ull; 13 typedef pair<int,int> pi; 14 ll n,K; 15 map<ll,ll> dd; 16 int main() 17 { 18 ll i; 19 scanf("%lld%lld",&n,&K); 20 for(i=0;n;n/=2,i++) 21 if(n%2) 22 dd[i]=n%2; 23 K-=dd.size();
24 if(K<0) 25 { 26 puts("No"); 27 return 0; 28 } 29 puts("Yes"); 30 while(K) 31 { 32 auto p=*dd.rbegin(); 33 //printf("%d %d\n",p.fi,p.se); 34 if(p.se<=K) 35 { 36 dd[p.fi-1]+=p.se*2; 37 dd.erase(p.fi);
38 K-=p.se; 39 } 40 else 41 { 42 while(K) 43 { 44 K--; 45 auto p2=*dd.begin(); 46 dd[p2.fi-1]+=2; 47 dd[p2.fi]--; 48 if(dd[p2.fi]==0) dd.erase(p2.fi); 49 } 50 } 51 } 52 for(auto it=dd.rbegin();it!=dd.rend();it++) 53 { 54 auto x=*it; 55 for(i=1;i<=x.se;i++) printf("%lld ",x.fi); 56 } 57 return 0; 58 }

Jamie and Binary Sequence (changed after round) - CodeForces 916B