Codeforces Round #202 B:Color the Fence
来源:互联网 发布:wifi广告路由器软件 编辑:程序博客网 时间:2024/05/15 03:24
贪心的题做的太少,碰到一点感觉都没有。 也是看了别人的题解才做。
对于此题,位数越长,那么数吧必定最大,那么cnt=v/mmin 就得到了最多的位数,那么最优的答案位数已经确定了。接下来就是相当于,我有cnt个空格,让你填1~9,9个数字,在满足限定条件的情况下,我要求最大值。这样子问题是不是一下变得很简单了呢? 限定条件是: 当前我取的数 对应的 值 不能超过总钱,并且选了这个数后,后面的位数不能受到影响,即位数不变。外层循环从cnt-1~0,内层循环9~1 满足条件就输出,高位的数字越大,肯定答案越大。
/*If I get TLE , it is good.If I get AC,it's NICE !*/#include <stdio.h>#include <iostream>#include <algorithm>#include <string.h>using namespace std;const int MAXN=1e6+100;int a[15]={0};int main(void){ int v; cin >> v; int mmin=MAXN; int maxcnt=0; for(int i=1;i<=9;i++) { scanf("%d",&a[i]); mmin=min(mmin,a[i]); // 求出最小的费用,确定位数 } if(v<mmin) { printf("-1\n"); return 0; } maxcnt=v/mmin; //其实下面的过程对位数的判断如果没想过可能一下子想不到,其实也就相当于把当前位后面的数字全遮掉,在限定条件下,然后去求最大可填的数字。 for(int i=maxcnt-1;i>=0;i--) { for(int j=9;j>=1;j--) { if(a[j]<=v && (v-a[j])/mmin >= i) { printf("%d",j); v-=a[j]; break; } } } puts("");}
阅读全文
0 0
- Codeforces Round #202 B:Color the Fence
- Codeforces Round #202 (Div. 2) B.Color the Fence
- Codeforces Round #202 (Div. 2) B. Color the Fence
- Codeforces Round #202 (Div. 2)B. Color the Fence
- Codeforces Round #202 (Div. 2)B. Color the Fence
- Codeforces Round #202 (Div. 2) B. Color the Fence
- Codeforces Round #202 (Div. 2) B. Color the Fence
- Codeforces Round #202 (Div. 2) B. Color the Fence
- CodeForces Round #202 (Div. 2) / ProblemSet 349B - B. Color the Fence 【贪心】
- Codeforces Round #202 (Div. 2) B. Color the Fence(贪心)
- Codeforces Round #202 (Div. 2)B. Color the Fence(贪心,模拟)
- CodeForces 349B - Color the Fence
- codeforces 349B Color the Fence
- CodeForces 349B Color the Fence
- CodeForces 349B Color the Fence
- CodeForces 349B Color the Fence
- CF#202DIV2:B. Color the Fence
- CF#202 div2 B Color the Fence
- HTTP请求报文(请求行、请求头、请求体)
- 2017.7.7
- 博客模版
- quill自定义图片上传
- js实现canvas绘制的图形的拖动效果
- Codeforces Round #202 B:Color the Fence
- 一入侯门深似海,不破楼兰终不回
- 文本四则运算解析工具与浮点数小数精度保留工具
- NIO的基本应用
- 【NOIP2015模拟11.3晚】喝喝喝
- hdu 1814
- 系统分布式情况下最终一致性方案梳理
- 什么是锚文本?
- int socket(int domain, int type, int protocol)参数详解