Jamie and Binary Sequence (changed after round) - CodeForces 916B
Posted hehe54321
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Jamie and Binary Sequence (changed after round) - CodeForces 916B相关的知识,希望对你有一定的参考价值。
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 ",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的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces 916B - Jamie and Binary Sequence (changed after round)
Codeforces Round #457 (Div. 2) BJamie and Binary Sequence
2018.3.5-6 knapsack problem, sequence alignment and optimal binary search trees