cf B. Color the Fence
http://codeforces.com/contest/349/problem/B
贪心
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int inf=<<; int a[];
int v,k;
int main()
{
while(scanf("%d",&v)!=EOF)
{
int min1=inf;
k=;
for(int i=; i<=; i++)
{
scanf("%d",&a[i]);
if(a[i]<min1)
{
min1=a[i];
k=i;
}
else if(a[i]==min1&&k<i)
{
k=i;
}
}
if(v<min1)
{
printf("-1\n");
continue;
}
if(v%min1==)
{
int m=v/min1;
for(int i=; i<=m; i++)
{
printf("%d",k);
}
printf("\n");
}
else
{
int len=v/min1;
for(int j=len; j>=; j--)
{
for(int i=; i>=; i--)
{
int x=v-a[i];
if(x<) continue;
if(x/min1==j-)
{
printf("%d",i);
v-=a[i];
break;
}
}
}
printf("\n");
}
}
return ;
}
cf B. Color the Fence的更多相关文章
- ACM Color the fence
Color the fence 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Tom has fallen in love with Mary. Now Tom w ...
- codeforces 349B Color the Fence 贪心,思维
1.codeforces 349B Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...
- NYOJ-791 Color the fence (贪心)
Color the fence 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Tom has fallen in love with Mary. Now Tom w ...
- 349B - Color the Fence
Color the Fence Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Su ...
- nyoj Color the fence
Color the fence 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Tom has fallen in love with Mary. Now Tom w ...
- Codeforces 349B - Color the Fence
349B - Color the Fence 贪心 代码: #include<iostream> #include<algorithm> #include<cstdio& ...
- nyoj 791——Color the fence——————【贪心】
Color the fence 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Tom has fallen in love with Mary. Now Tom w ...
- Codeforces D. Color the Fence(贪心)
题目描述: D. Color the Fence time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- CF 484E - Sign on Fence
E. Sign on Fence time limit per test 4 seconds memory limit per test 256 megabytes input standard in ...
随机推荐
- directive 指令
参考文章 : http://www.zouyesheng.com/angular.html#toc20 18. 自定义指令directive http://blog.jobbole.com/62 ...
- MYSQL错误解决:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' ( ...
- 中国IC业“芯”结:IC小国真能赶追韩美日么?
集成电路是关系到国民经济和社会发展的战略性.基础性和先导性产业,是培育发展战略性新兴产业.推动信息化和工业化深度融合的核心与基础.因此,我 国历来就十分重视集成电路产业的培育和发展,在这方面投入了大量 ...
- 51单片机引脚ALE/PROG/PSEN/EA/Vpp
51单片机的4个控制引脚,其中一个引脚是复位引脚(RST/Vpd),RST是复位引脚,当RST输入端保持2个机器周期以上高电平时,就实现复位. ALE/PROG是地址锁存允许信号输出端,在读写外部存储 ...
- 在WPF中使用AForge.net控制摄像头拍照
原文:在WPF中使用AForge.net控制摄像头拍照 利用AForge.net控制摄像头拍照最方便的方法就是利用PictureBox显示摄像头画面,但在WPF中不能直接使用PictureBox.必须 ...
- Visual Studio中的lib的链接顺序
描述:如果有一个exe工程,它依赖于A.lib,B.lib,A.lib和B.DLL我同样有他们的源码工程.依赖顺序是这样的exe->A.lib->B.DLL.那么如果我改动了B的源码,编译 ...
- Hello Bolg!
初来乍到,将就闹点小情绪吧 博客, 作为一个即将毕业的小码农, 第一次写这东西似乎生涩了点. 而且第一眼看到这东西还觉得特玄乎,不过“化抽象为具体, 化复杂为简单”不正是自己的职业操守吗. 于是, 我 ...
- Exchange Server 2010/2013功能差异
- python中os模块常用方法
#!/usr/bin/python## os module test import os print 'os.name: ', os.nameprint 'os.getcwd(): ', os.get ...
- Thrift的安装和简单演示样例
本文仅仅是简单的解说Thrift开源框架的安装和简单使用演示样例.对于具体的解说,后面在进行阐述. Thrift简述 ...