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 贪心构造的更多相关文章

  1. URAL 1995 Illegal spices

    构造. 前$n-k$个都是$1$,最后$k$个进行构造,首先选择填与上一个数字一样,如果不可行,那么这一格的值$+1$. #include<map> #include<set> ...

  2. 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation

    题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...

  3. 贪心/构造/DP 杂题选做

    本博客将会收录一些贪心/构造的我认为较有价值的题目,这样可以有效的避免日后碰到 P7115 或者 P7915 这样的题就束手无策进而垫底的情况/dk 某些题目虽然跟贪心关系不大,但是在 CF 上有个 ...

  4. 贪心/构造/DP 杂题选做Ⅱ

    由于换了台电脑,而我的贪心 & 构造能力依然很拉跨,所以决定再开一个坑( 前传: 贪心/构造/DP 杂题选做 u1s1 我预感还有Ⅲ(欸,这不是我在多项式Ⅱ中说过的原话吗) 24. P5912 ...

  5. 贪心/构造/DP 杂题选做Ⅲ

    颓!颓!颓!(bushi 前传: 贪心/构造/DP 杂题选做 贪心/构造/DP 杂题选做Ⅱ 51. CF758E Broken Tree 讲个笑话,这道题是 11.3 模拟赛的 T2,模拟赛里那道题的 ...

  6. 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 ...

  7. Codeforces 1082D Maximum Diameter Graph (贪心构造)

    <题目链接> 题目大意:给你一些点的最大度数,让你构造一张图,使得该图的直径最长,输出对应直径以及所有的边. 解题分析:一道比较暴力的构造题,首先,我们贪心的想,要使图的直径最长,肯定是尽 ...

  8. hdu 4982 贪心构造序列

    http://acm.hdu.edu.cn/showproblem.php?pid=4982 给定n和k,求一个包含k个不相同正整数的集合,要求元素之和为n,并且其中k-1的元素的和为完全平方数 枚举 ...

  9. Codeforces Round #335 (Div. 2) D. Lazy Student 贪心+构造

    题目链接: http://codeforces.com/contest/606/problem/D D. Lazy Student time limit per test2 secondsmemory ...

随机推荐

  1. 离散化&&逆序数对

    题目:http://www.fjutacm.com/Problem.jsp?pid=3087 #include<stdio.h> #include<string.h> #inc ...

  2. Python多态、鸭子类型

    一.多态 多态指的是一类事物有多种形态. 动物有多种形态:人,狗,猪 import abc class Animal(metaclass=abc.ABCMeta): #同一类事物:动物 @abc.ab ...

  3. 多播知识by 陈胜君

    简单的讲一下多拨的说明:一.多拨分物理多拨和虚拟多拨. 物理多拨是电信老套餐,就是一个宽带支持四个内网设备同时拨号上网,即2004年以前,允许家里四台电脑直接连LAN网口启动拨号,同时允许四拨在线.现 ...

  4. IDEA配置toString方法

    1.toString JSON带父类toString public java.lang.String toString() { final java.lang.StringBuilder sb = n ...

  5. jekyll简单使用

    jekyll build # => 当前文件夹中的内容将会生成到 ./site 文件夹中. jekyll build –destination <destination> # =&g ...

  6. Linux 基础——常用的Linux网络命令

    一.学Linux网络命令有什么好处 网络的出现,我们的生活更方便了,处理事情的效率也越来越高,也可以看到全世界文化的差异.同时我们接受新事物的信息越来越来强,新事物的信息也越来越来多.网络对于我们尔等 ...

  7. Single Image Haze Removal(图像去雾)-CVPR’09 Best Paper

    公式推导 paper闪光点 找到了一个很简洁的假设. paper不足 代码跑起来很慢.据说2010年的ECCV那篇是改进的.

  8. CSU 1351 Tree Counting

    原题链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1351 DP题,毫无疑问.由于动态规划题目做得少.不熟悉,刚开始自己用f[i]表示用 i ...

  9. JS(vue iview)分页解决方案

    JS(vue iview)分页解决方案 一.解决思路 使用分页组件 使用组件API使组件自动生成页面数量 调用组件on-change事件的返回值page 将交互获得的数组存在一个数组list中 通过p ...

  10. socket.io分布式

    socket.io是目前较为流行的web实时推送框架,其基于nodejs语言开发,底层用engine.io实现. 借助nodejs语言异步的特性,其获得了不错的性能.但单个实例的socket.io依然 ...