【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 ...
随机推荐
- Anaconda 安装和使用Numpy、Scipy、pandas、Scikit-learn
Anaconda 安装和使用 https://www.cnblogs.com/liruihuan/p/9101613.html 最近看了些关于数据分析的书,想系统的整理下相关知识,算是学习笔记吧,也希 ...
- [模板]平衡树splay
气死我了,调了一个下午+两节课,各种大大小小的错误,各种调QAQ,最后总之是调出来了. 其实就是一个双旋操作,然后其他就是左儿子<当前节点<右儿子,剩下就是细节了. 题干: 题目描述 您需 ...
- IDEA maven不能下载源码:" can not download source"问题
用IDEA无法下载源码,可以在命令行项目根目录下,执行如下命令 :mvn dependency:resolve -Dclassifier=sources下载 也可以在idea设置中设置为自动下载源码
- 浅谈IO优化
三层结构 磁盘(存储).VM(卷管理)和文件系统.专有名词不好理解,打个比方说:磁盘就相当于一块待用的空地:LVM相当于空地上的围墙(把空地划分成多个部分):文件系统则相当于每块空地上建的楼房(决定了 ...
- ashx 文件的使用
它就类似.aspx文件,用于处理传入到服务器的HTTP请求,但它不会像.aspx文件那样要返回处理结果和大量HTML,它可以返回简单的字符串.图片等. 百度百科定义链接:http://baike.ba ...
- 【NOIP练习赛】学习
[NOIP练习赛]T3.学习 Description 巨弱小 D 准备学习,有 n 份学习资料给他看,每份学习资料的 内容可以用一个正整数 ai 表示.小 D 如果在一天内学习了多份资料, 他只能记住 ...
- Java常用类库(一) : Object 和日期类的简单使用
顶哥说:Java是世界的,但项目不是! Java有非常多的类库,而我们不会也不用都去学习,毕竟你也仅仅掌握了你手机20%的功能却足够你使用,不是吗? 今天介绍以下类: l Object l Dat ...
- C#语言最基础的认识变量
变量是指一块存储数据的内存空间,并且该内存区域的数据内容可以发生变化. 变量是必须先声明后赋值. 基本的语法:数据类型+变量名: 变量名=数据: 简单的使用技巧:声明赋值简写 Static void ...
- 提高mysql千万级大数据SQL查询优化几条经验
凯哥java 微信号 kaigejava 功能介绍 ...
- JS——offset
1.offsetWidth.offsetHeight返回盒子宽度和高度,包括padding与border,不包括margin 2.offsetLeft.offsetTop返回盒子距离定位盒子的x轴方向 ...