Codeforces Round #202 (Div. 2)B-贪心
来源:互联网 发布:丁芙妮黑历史 知乎 编辑:程序博客网 时间:2024/05/09 08:39
B:先找数量多的,然后根据剩余的是否能跟现有的凑成一个更大的
下面是代码:
#include<iostream>#include<set>#include<map>#include<vector>#include<queue>#include<cmath>#include<climits>#include<cstdio>#include<string>#include<cstring>#include<algorithm>typedef long long LL;using namespace std;const int M=100050;struct node{ int p,i;} pri[14];bool cmp(node a,node b){ if(a.p!=b.p)return a.p<b.p; else return a.i>b.i;}int main(){ int v,i; while(scanf("%d",&v)!=EOF) { for(i=1; i<=9; i++) scanf("%d",&pri[i].p),pri[i].i=i; sort(pri+1,pri+10,cmp); int n=v/pri[1].p; if(n==0)printf("-1\n"); else { int res=v-n*pri[1].p,maxx=pri[1].i,kk=0; while(1) { int temp=-1; maxx=pri[1].i; for(i=1; i<=9; i++) { if(res+pri[1].p>=pri[i].p&&maxx<pri[i].i) { temp=i; maxx=pri[i].i; } } if(temp==-1)break; res=res-pri[temp].p+pri[1].p; printf("%d",maxx); kk++; } for(; kk<n; kk++)printf("%d",pri[1].i); printf("\n"); } } return 0;}
- Codeforces Round #202 (Div. 2)B-贪心
- Codeforces Round #428 (Div. 2) B 贪心
- Codeforces Round #202 (Div. 2)(B)贪心,思维
- CodeForces Round #202 (Div. 2) / ProblemSet 349B - B. Color the Fence 【贪心】
- Codeforces Round #109 (Div. 2) B (贪心)
- Codeforces Round #111 (Div. 2) B Unlucky Ticket (贪心)
- Codeforces Round #277.5 (Div. 2)---B. BerSU Ball (贪心)
- Codeforces Round #307 (Div. 2) B. ZgukistringZ (贪心 + 暴力)
- Codeforces Round #334 (Div. 2) B. More Cowbell (贪心)
- Codeforces Round #331 (Div. 2) B. Wilbur and Array (贪心)
- Codeforces Round #342 (Div. 2)(B)贪心
- Codeforces Round #345 (Div. 2) B. Beautiful Paintings【贪心】
- Codeforces Round #347 (Div. 2) B Rebus (贪心构造)
- Codeforces Round #349 (Div. 2)(B)贪心
- Codeforces Round #301 (Div. 2) B. School Marks(贪心)
- Codeforces Round #368 (Div. 2)(B. Bakery 贪心)
- Codeforces Round #334 (Div. 2) B. More Cowbell (贪心)
- 【Codeforces Round #373 (Div. 2) 】【贪心】B. Anatoly and Cockroaches
- java调用shell
- SetTimer和Sleep是两回事
- google 搜索引擎的关键字
- WordPress图片防盗链的几种方法
- linux中,管道能够在同一进程中进行通信吗?
- Codeforces Round #202 (Div. 2)B-贪心
- 第十一周项目3-2-反序输出一个10000000以内的数
- MediaRecorder
- 安卓自测试题——第九期
- 详谈Objective-C内存管理机制
- ios webview清除缓存
- 使用Spring的LdapTemplate进行LDAP操作
- 安卓自测试题——第十期
- Oracle的锁表与解锁