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");
}

转载于:https://www.cnblogs.com/qscqesze/p/5370308.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值