【Codeforces 349B】Color the Fence
【链接】 我是链接,点我呀:)
【题意】
让你组成一个只由1~9组成的数字
每个数字需要的paint数字给定。
让你组成一个最大的数字,且所有数字的paint的总和不超过v.
【题解】
先求出a中的最小值mi
最后的长度显然就是a/mi啦
然后从高位到低位,优先让高位优先选择大的数字就好.
(判断这一位能否为i的条件就是,后面的所有位置全都选择mi
看看会不会超过剩余的paint数量就好
【代码】
import java.io.*;
import java.util.*;
public class Main {
static InputReader in;
static PrintWriter out;
public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
}
static int N = 10;
static int L = (int)1e6;
static class Task{
int v,mi;
int a[],b[];
public void dfs(int dep,int rest) {
if (dep==0) return;
for (int i = 9;i >= 1;i--) {
if (rest-a[i]-(dep-1)*mi>=0) {
b[dep] = i;
dfs(dep-1,rest-a[i]);
return;
}
}
}
public void solve(InputReader in,PrintWriter out) {
a = new int[N+10];
b = new int[L+10];
v = in.nextInt();
for (int i = 1;i <= 9;i++) a[i] = in.nextInt();
mi = a[1];
for (int i = 1;i <= 9;i++) mi = Math.min(a[i], mi);
int len = v/mi;
if (len==0)
out.println(-1);
else {
dfs(len,v);
for (int i = len;i >= 1;i--) out.print(b[i]);
}
}
}
static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer;
public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
}
public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
【Codeforces 349B】Color the Fence的更多相关文章
- 【Codeforces 1132C】Painting the Fence
Codeforces 1132 C 题意:给一些区间\([l_i,r_i]\),从中删掉两个,求剩下的区间最多能够覆盖的格子数量. 思路:首先枚举第一个删掉的区间,然后我们可以通过差分来求出每个格子被 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 234F】Fence
[题目链接]:http://codeforces.com/problemset/problem/234/F [题意] 你有n块板要凃油漆; 然后每块板有高度h[i];(宽度都为1) 然后每块板只能凃同 ...
- 【39.66%】【codeforces 740C】Alyona and mex
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【34.57%】【codeforces 557D】Vitaly and Cycle
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【27.91%】【codeforces 734E】Anton and Tree
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【47.95%】【codeforces 554C】Kyoya and Colored Balls
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 758B】Blown Garland
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 750D】New Year and Fireworks
time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard ...
随机推荐
- Android 触摸提示音【转】
本文转载自:http://blog.csdn.net/Jin_HeZai/article/details/46791567 近期任务,涉及Android触摸提示音. 首先,定位源码目标.很显然的,在原 ...
- 洛谷P2340 奶牛会展
题目背景 奶牛想证明它们是聪明而风趣的.为此,贝西筹备了一个奶牛博览会,她已经对N 头奶牛进行 了面试,确定了每头奶牛的智商和情商. 题目描述 贝西有权选择让哪些奶牛参加展览.由于负的智商或情商会造成 ...
- zabbix监控kafka消费
一.Kafka监控的几个指标 1.lag:多少消息没有消费 lag=logsize-offset 2.logsize:Kafka存的消息总数 3.offset:已经消费的消息 Kafka管理工具 介绍 ...
- 【已解决】Makefile执行过程中出错:make: *** No rule to make target ` ‘, needed by xxx. Stop(转载)
转自: http://www.crifan.com/makefile_error_make_no_rule_to_make_target_needed_by_stop/ [问题] 有个已有的Makef ...
- json-server的关系图谱详解(Relationships)
json-server的关系图谱 json-server是非常好用的一款模拟REST API的工具,文档也很详细和全面.详情:json-server而其中的关系图谱是它非常强大的一个功能,可以非常方便 ...
- 用vue-cli快速构建项目
用vue-cli脚手架快速构建项目的过程:1.首先要在node的环境下安装: 1>安装node:https://nodejs.org/en/(带npm,但是npm太慢了,建议安装cnpm,cnp ...
- OpenResty / Nginx模块,Lua库和相关资源的列表
OpenResty / Nginx模块,Lua库和相关资源的列表 什么是OpenResty OpenResty是一个成熟的网络平台,它集成了标准的Nginx核心,LuaJIT,许多精心编写的Lua库, ...
- Linux命令(005) -- kill、pkill和killall的比较
kill命令用来“杀掉”指定进程PID的进程.终止一个前台进程可以使用Ctrl+C,终止一个后台进程就须用kill命令.kill命令是通过向进程发送指定的信号来结束相应进程的.在默认情况下,kill命 ...
- Cookie localStorage sessionStorage
三者的异同 特性 Cookie localStorage sessionStorage 数据的生命期 可设置失效时间,默认是关闭浏览器后失效 除非被清除,否则永久保存 仅在当前会话下(tab标签页)有 ...
- 实现div毛玻璃背景
毛玻璃效果 ios里毛玻璃效果的使用非常多,本文介绍一个实现div毛玻璃背景的方法 CSS3 Filter CSS3的Filter主要用在图像的特效处理上,默认值为none,还有以下备选项: 1. ...