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. django【ORM】model字段类型

    1.AutoField 一个自增的IntegerField,一般不直接使用,Django会自动给每张表添加一个自增的primary key. 2.BigIntegerField 64位整数, -922 ...

  2. python模块之itertools

    在循环对象和函数对象中,我们了解了循环器(iterator)的功能.循环器是对象的容器,包含有多个对象.通过调用循环器的next()方法 (__next__()方法,在Python 3.x中),循环器 ...

  3. linux 端口设置结构体 struc

      目录(?)[-] 一 输入模式 三输出模式 四控制模式 六特殊的控制字符 字符 TIME和MIN值 通过shell访问终端模式 终端速度 其他函数 使用termios结构的密码程序   termi ...

  4. Morris Traversal方法遍历

    实现二叉树的遍历且只需要O(1)的空间. 参考:http://www.cnblogs.com/AnnieKim/archive/2013/06/15/MorrisTraversal.html

  5. LightOJ 1369 Answering Queries(找规律)

    题目链接:https://vjudge.net/contest/28079#problem/P 题目大意:给你数组A[]以及如下所示的函数f: long long f( int A[], int n  ...

  6. CNN基础

    CNN一般结构 卷积层作用: 1) 提取不同维度的特征,组合不同维度特征,其本质是卷积核,因此,学习一个有效的总卷积核是训练卷积层主要工作 2)寻找不同位置,不同大小的特征 3) 根据卷积核参数计算上 ...

  7. 安迪的第一个字典(UVa10815)

    题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_prob ...

  8. beautifulsoup简单用法

    原文地址 http://www.cnblogs.com/yupeng/p/3362031.html 这篇文章讲的也很全 http://www.cnblogs.com/twinsclover/archi ...

  9. webpack2.0构建vue2.0超详细精简版

    原文地址:http://blog.csdn.net/dahuzix/article/details/55549387 npm init -y 初始化项目 安装各种依赖项 npm install --s ...

  10. 【BZOJ】4311: 向量(线段树分治板子题)

    题解 我们可以根据点积的定义,垂直于原点到给定点构成的直线作一条直线,从正无穷往下平移,第一个碰到的点就是答案 像什么,上凸壳哇 可是--动态维护上凸壳? 我们可以离线,计算每个点能造成贡献的一个询问 ...