codeforces 509C Sums of Digits (贪心对位操作)
来源:互联网 发布:java的缺点知乎 编辑:程序博客网 时间:2024/05/29 13:39
题意:
给出n个数字,这些数字数由另外n个数字各个位数的和得来的。求另外n个数,要尽量小,而且要递增。
题解:
贪心,对位进行操作,有点像数位dp。
#include<iostream>#include<math.h>#include<stdio.h>#include<algorithm>#include<string.h>#include<vector>#include<map>using namespace std;typedef long long ll;const int oo=0x3f3f3f3f;const ll OO=1LL<<61;const ll MOD=1000000007;const int maxn=505;int a[maxn];int bit[maxn],len;int cal(int n){ int i; for(i=1;n;i++) { while(bit[i]<9&&n) { bit[i]++; n--; } if(i>len&&!n)len=i; }}void output(){ for(int i=len;i>=1;i--) printf("%d",bit[i]); puts("");}int main(){ int n; while(scanf("%d",&n)!=EOF) { memset(bit,0,sizeof bit); for(int i=1;i<=n;i++) scanf("%d",&a[i]); cal(a[1]); output(); for(int i=2;i<=n;i++) { if(a[i]>a[i-1]) cal(a[i]-a[i-1]); else { int k=1,t=a[i]-a[i-1]; while(1) { if(k>len)len=k; if(bit[k]<9&&t>0) { bit[k]++; t--; cal(t); break; } t+=bit[k]; bit[k]=0; k++; } } output(); } } return 0;}/***/
0 0
- codeforces 509C Sums of Digits (贪心对位操作)
- Codeforces 509c Sums of Digits 贪心
- Codeforces 509C. Sums of Digits 贪心枚举
- Codeforces 509C. Sums of Digits 贪心 + 模拟
- Sums of Digits - CodeForces 509 C
- codeforces 509C Sums of Digits
- codeforces 509C C. Sums of Digits(数位dp+贪心+枚举)
- 【构造】Codeforces Round #289 509C Sums of Digits
- codeforces 289 C Sums of Digits
- Codeforces Round #289 (Div. 2, ACM ICPC Rules)C. Sums of Digits——贪心+模拟
- C - Sums of Digits
- Codeforces Round #289 C. Sums of Digits(构造)
- Codeforces Round #289 (Div. 2, ACM ICPC Rules)C. Sums of Digits
- Codeforces Round #289 (Div. 2, ACM ICPC Rules) C. Sums of Digits
- Codeforces Round #289 (Div. 2, ACM ICPC Rules) C. Sums of Digits
- [cf509C]Sums of Digits
- [CF]Sums of Digits
- Codeforces #277.5 (Div. 2) C. Given Length and Sum of Digits...(简单贪心)
- ZOJ 3702
- 《如果梵高生在中国》笔记
- UVa #11400 Lighting System Design (例题9-6)
- 背包九讲
- delphi 中的一个线程池单元的归纳说明
- codeforces 509C Sums of Digits (贪心对位操作)
- Zend Studio12.0破解方法(附网盘下载)
- ZOJ 2283 Challenge of Wisdom
- Vmware vSphere常见问题及解决办法
- C++ STL 算法:对所有元素排序
- 国内各大城市的IT行业特色
- Java—读写锁的简单使用
- IsDebuggerPresent官方出处
- hadoop/spark调优以及遇到的问题