【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 ...
随机推荐
- 【Codeforces】 Round #374 (Div. 2)
Position:http://codeforces.com/contest/721 我的情况 开始还是rank1,秒出C.(11:00机房都走光了,我ma到11:05才走,只打了一个小时) 结果.. ...
- 【POJ 3784】 Running Median
[题目链接] http://poj.org/problem?id=3784 [算法] 对顶堆算法 要求动态维护中位数,我们可以将1-M/2(向下取整)小的数放在大根堆中,M/2+1-M小的数放在小根堆 ...
- MSP430 G2553 Timer 中断总结
目前总共用到了四个中断向量,我觉得已经把G2553的所有定时器中断都用到了. 定时器有两个,TA0与TA1,每个定时器又有两个中断向量 1,CCR0到达时的中断,在计数模式时候很有用,平时定时器的基本 ...
- 在datagrid中的toolbar添加输入框
转自:https://blog.csdn.net/u013178480/article/details/72358551 <code class="language-html" ...
- ubuntu系统快捷键设置
1.打开'系统设置' 2.点击键盘 3.选择快捷键,查看和修改对应的快捷键.
- 51nod 1222 莫比乌斯反演
思路: yhx找的反演题 题解已经烂大街了 #pragma GCC optimize("O3") //By SiriusRen #include <bits/stdc++.h ...
- mysql远程服务器访问数据库
创建一个MySQL用户,并设置可以远程访问 grant usage on *.* to 'fred'@'localhost' identified by 'fred';//创建用户fred密码ferd ...
- asp.net mvc 最简单身份验证 [Authorize]通过的标准
[Authorize] public ContentResult Index2() { return Content("验证通过了"); } 经常能够看到某个Controler下的 ...
- ubuntu上Hadoop三种运行模式的部署
Hadoop集群支持三种运行模式:单机模式.伪分布式模式,全分布式模式,下面介绍下在Ubuntu下的部署 (1)单机模式 默认情况下,Hadoop被配置成一个以非分布式模式运行的独立JAVA进程,适合 ...
- TensorFlow学习---入门(一)-----MNIST机器学习
参考教程:http://www.tensorfly.cn/tfdoc/tutorials/mnist_beginners.html 数据下载地址:http://wiki.jikexueyuan.com ...