Codeforces Round #202 (Div. 2) B:http://codeforces.com/problemset/problem/349/B

题意:给你一些颜料,然后你可以用这些颜料画一些数字,画每个数字的颜料是不一样的,然后问你用这些颜料可以画出的最大的数。

题解:和容易想到,直接用贪心,数字最大,首先要使得数字的位数最多,所以要选择需要颜料最少的数字来话,此题有一个好处就是,就是不用考虑前导零的情况,数的位数确定之后,就可以用剩余的颜料来调整数字,从高位到低位,每一次把把尽可能大的数字放在高位。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[],v;
int minn,pos,ct;
int ans[],top;
int main(){
while(~scanf("%d",&v)){
minn=1e7;
for(int i=;i<=;i++){
scanf("%d",&a[i]);
if(minn>=a[i]){
minn=a[i];
pos=i;
}
}
if(v<minn){
printf("-1\n");continue;
}
ct=v/minn;
int temp=v-ct*minn;
for(int i=;i<=ct;i++)
ans[i]=pos;
top=;
// printf("%d %d %d\n",ct,temp,minn);
while(temp>){
int tp=;
top++;
if(top>ct)break;
for(int i=;i<=;i++){
if(a[i]-minn<=temp)
tp=i;
}
if(tp==)break;
else {
ans[top]=tp;
temp-=(a[tp]-minn);
}
}
for(int i=;i<ct;i++){
printf("%d",ans[i]);
}
printf("%d\n",ans[ct]);
}
}

Color the Fence的更多相关文章

  1. ACM Color the fence

    Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Tom has fallen in love with Mary. Now Tom w ...

  2. codeforces 349B Color the Fence 贪心,思维

    1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...

  3. NYOJ-791 Color the fence (贪心)

    Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Tom has fallen in love with Mary. Now Tom w ...

  4. 349B - Color the Fence

    Color the Fence Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Su ...

  5. nyoj Color the fence

    Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Tom has fallen in love with Mary. Now Tom w ...

  6. Codeforces 349B - Color the Fence

    349B - Color the Fence 贪心 代码: #include<iostream> #include<algorithm> #include<cstdio& ...

  7. nyoj 791——Color the fence——————【贪心】

    Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Tom has fallen in love with Mary. Now Tom w ...

  8. Codeforces D. Color the Fence(贪心)

    题目描述: D. Color the Fence time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  9. B. Color the Fence

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  10. codeforces B. Color the Fence 解题报告

    题目链接:http://codeforces.com/problemset/problem/349/B 题目意思:给定v升的颜料和9个需要花费ad 升的颜料,花费ad 升的颜料意味着得到第d个数字,现 ...

随机推荐

  1. android 57 QQ登录

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...

  2. Redhat 官方Performance_Tuning_Guide

    https://access.redhat.com/documentation/zh-CN/Red_Hat_Enterprise_Linux/6/html/Performance_Tuning_Gui ...

  3. spring aop 如何切面到mvc 的controller--转载

    原文:http://yjian84.iteye.com/blog/1920787 网上搜罗半天,不知道什么原因,看了源码,好像他们说的controller 是不受代理的,也对哈,不知道怎么办,于是在h ...

  4. iOS-本地推送(本地通知)

    第一步:注册本地通知: // 设置本地通知 + (void)registerLocalNotification:(NSInteger)alertTime { UILocalNotification * ...

  5. Some code changes cannot be hot swapped into a running virtual machine,

    翻译一下:不能热交换到运行虚拟机,一些代码变化不能热交换到运行虚拟机,如更改名称或介绍的方法错误运行代码.解决方法:增加.删除类文件或者在一个类中增加.删除方法时,是不能够热部署到服务上的.这时候需要 ...

  6. json-lib-2.4-jdk15.jar maven

    最近自己将一个web项目装换到使用mevan自动管理. 遇到了一个json包导入的问题.最终解决如下: <!-- https://mvnrepository.com/artifact/net.s ...

  7. Markdown写接口文档,自动添加TOC

    上回说到,用Impress.js代替PPT来做项目展示.这回换Markdown来做接口文档好了.(不敢说代替Word,只能说个人感觉更为方便)当然,还要辅之以Git,来方便版本管理. Markdown ...

  8. order by 自定义排序

    使用order by排序,有时候不是根据字符或数字顺序,而是根据实际要求排序. 例如有客户A,B,C,我希望排序结果是B,C,A,那么就要通过自定义的规则排序. 第一种方法,可以构造一张映射表,将客户 ...

  9. ActionResult 常见问题

    1:在Asp.net Mvc 2中由于对数据的保护,当返回类型为JsonResult时 ,默认情况下request需要为post.(可使用   return Json(person,JsonReque ...

  10. C#重载重写

    overload:重载指的是同一个类中有两个或多个名字相同但是参数不同的方法,(注:返回值不能区别函数是否重载),重载没有关键字.override:过载也称重写是指子类对父类中虚函数或抽象函数的“覆盖 ...