URAL 1995 Illegal spices 贪心构造
Illegal spices
题目连接:
http://acm.timus.ru/problem.aspx?space=1&num=1995
Description
Jabba: Han, my boy, you disappoint me. Why haven’t you paid me? And why did you fry poor Greedo?
Han: Look, Jabba, next time you wanna talk to me, come see me yourself. Don’t send one of these twerps.
Jabba: Han, I can’t make exceptions. What if everyone who smuggled for me dropped their cargo at the first sign of an imperial starship?
Han Solo and his flight mechanic Chewbacca are experienced smugglers. They have spent several years working for a crime boss of the Tatooine planet Jabba the Hutt. But even the best of the best blow it sometimes.
During a flight, captain Solo’s ship called «Millennium Falcon» met imperial customs officers. Han was transporting cargo consisting of n bags with spices. Each bag weighs an integer number of kilograms. Han noticed the customs officers from above and decided to dump the cargo into space.
Captain Solo dumped the first bag. Then he decided to take a risk and leave part of the cargo in the secret section. Han was checking each bag, and during that he was counting how many bags he has already checked (including the first one) that were lighter than the current one. He left a bag on the ship only if that number was at least p percent from the total number of the bags that have already been checked. Using this strategy Solo hoped to leave the most important part of the cargo on the ship.
As a result, he was left with only k bags that fit in the secret section easily. The customs officers couldn’t find anything and they left the «Millennium Falcon».
Now Han understands that he has lost quite a large part of the cargo and that Jabba is going to be quite displeased. Unfortunately, he doesn’t remember the total weight of the transported goods. Help Han find the minimum possible total weight just to show him how big a loser he is.
Input
The first line contains integers n and k (1 ≤ k < n ≤ 10 5). The second line contains integer p (1 ≤ p ≤ 100).
Output
In the first line, print the answer to the problem. In the second line print n space-separated integers — the bags’ weights in kilograms in the order Captain Solo checked them, including the first bag. If there are multiple sequences that meet the problem statement, you can print any of them. It is guaranteed that at least one such sequence exists.
Sample Input
3 1
50
Sample Output
4
1 2 1
Hint
题意
有n个物品,然后有k个东西留了下来
如果x/(i-1)<p的话就会被留下来,其中x是前面小于这个数的数量
要求你构造一组解,使得总和最小,保证存在一组解
题解:
贪心,首先前面的肯定全是1嘛,这些全扔了就好
后面的我们保证不扔的话,那么就不断增大,直到满足就好了嘛
显然后面是递增的,这个也很好写。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int w[maxn];
int main()
{
int n,k,p;
scanf("%d%d%d",&n,&k,&p);
k = n - k;
int now = 1;
int num = 0;
for(int i=1;i<=n;i++)
{
if(i<=k)
{
w[i]=1;
num++;
}
else
{
if(100*num>=p*(i-1))w[i]=now+1;
else
{
now++;
num=i-1;
w[i]=now+1;
}
}
}
long long ans = 0;
for(int i=1;i<=n;i++)
ans = ans + w[i];
cout<<ans<<endl;
for(int i=1;i<=n;i++)
{
if(i==1)printf("%d",w[i]);
else printf(" %d",w[i]);
}
printf("\n");
}
URAL 1995 Illegal spices 贪心构造的更多相关文章
- URAL 1995 Illegal spices
构造. 前$n-k$个都是$1$,最后$k$个进行构造,首先选择填与上一个数字一样,如果不可行,那么这一格的值$+1$. #include<map> #include<set> ...
- 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation
题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...
- 贪心/构造/DP 杂题选做
本博客将会收录一些贪心/构造的我认为较有价值的题目,这样可以有效的避免日后碰到 P7115 或者 P7915 这样的题就束手无策进而垫底的情况/dk 某些题目虽然跟贪心关系不大,但是在 CF 上有个 ...
- 贪心/构造/DP 杂题选做Ⅱ
由于换了台电脑,而我的贪心 & 构造能力依然很拉跨,所以决定再开一个坑( 前传: 贪心/构造/DP 杂题选做 u1s1 我预感还有Ⅲ(欸,这不是我在多项式Ⅱ中说过的原话吗) 24. P5912 ...
- 贪心/构造/DP 杂题选做Ⅲ
颓!颓!颓!(bushi 前传: 贪心/构造/DP 杂题选做 贪心/构造/DP 杂题选做Ⅱ 51. CF758E Broken Tree 讲个笑话,这道题是 11.3 模拟赛的 T2,模拟赛里那道题的 ...
- Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)
A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- Codeforces 1082D Maximum Diameter Graph (贪心构造)
<题目链接> 题目大意:给你一些点的最大度数,让你构造一张图,使得该图的直径最长,输出对应直径以及所有的边. 解题分析:一道比较暴力的构造题,首先,我们贪心的想,要使图的直径最长,肯定是尽 ...
- hdu 4982 贪心构造序列
http://acm.hdu.edu.cn/showproblem.php?pid=4982 给定n和k,求一个包含k个不相同正整数的集合,要求元素之和为n,并且其中k-1的元素的和为完全平方数 枚举 ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 贪心+构造
题目链接: http://codeforces.com/contest/606/problem/D D. Lazy Student time limit per test2 secondsmemory ...
随机推荐
- Mysql储存过程4:mysql变量设置
默认全局变量是两个@@开头, 可用show variables查看所有默认变量: @@user #declare定义变量只能用在储存过程中 #declare 变量名 数据类型 可选类型 declare ...
- 如何通过掩码计算可用的IP数量
假设掩码是28,28也就是28个1.本身掩码是255.255.255.255那么转换成二进制也就是 11111111,11111111,11111111,11111111 那么28个1也就是: 111 ...
- dlmalloc(一)【转】
转自:http://blog.csdn.net/ycnian/article/details/12971863 我们写过很多C程序了,经常会分配内存.记得刚学C语言时老师说过,可以向两个地方申请内存: ...
- 64_p8
python2-cotyledon-tests-1.6.7-2.fc26.noarch.rpm 12-Feb-2017 10:28 23182 python2-couchdb-1.0-6.fc26.n ...
- 343.Integer Break---dp
题目链接:https://leetcode.com/problems/integer-break/description/ 题目大意:给定一个自然数,将其分解,对其分解的数作乘积,找出最大的乘积结果. ...
- linux下使用privoxy将socks转为http代理
此博客不在更新,我的博客新地址:www.liuquanhao.com ----------------------------------------------------------------- ...
- Metro应用Json数据处理
Windows Phone 8 或者 Windows 8 平台对JSON数据的处理方式基本是一致的,需要使用DataContractJsonSerializer类将对象的实例序列化为JSON字符串,并 ...
- golang-goroutine和channel
goroutine 在go语言中,每一个并发的执行单元叫做一个goroutine 这里说到并发,所以先解释一下并发和并行的概念: 并发:逻辑上具备同时处理多个任务的能力 并行:物理上在同一时刻执行多个 ...
- Weex 版扫雷游戏开发
扫雷是一个喜闻乐见的小游戏,今天在看 Weex 文档的过程中,无意中发现用 Weex 完全可以开发一个扫雷出来.当然这个扫雷和 Windows 那个有一点差距,不过麻雀虽小五脏俱全,随机布雷.自动挖雷 ...
- python中__dict__与dir()的区别
在python中__dict__与dir()都可以返回一个对象的属性,区别在于: __dict__是对象的一个属性,而dir()是一个built-in的方法: __dict__返回一个对象的属性名和值 ...