URAL1995-Illegal spices(贪心构造)

来源:互联网 发布:旧货市场淘宝 编辑:程序博客网 时间:2024/06/11 22:22

1995. Illegal spices

Time limit: 1.0 second
Memory limit: 64 MB
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 ≤ 105). 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

inputoutput
3 150
41 2 1
Problem Author: Denis Dublennykh (prepared by Oleg Dolgorukov)


题意:n个袋子,现在扔掉n-k个最后留下k个。首先第一个必须要扔;然后对于后面的第i个,统计前i-1个中比第i个重量轻的个数cnt,若cnt所占的比例即cnt/(i-1)>=p则这个袋子不扔。现在告诉起始有n个袋子最后剩下k个,让你构造n个袋子的重量使得总重量最小。
解题思路:首先第一个肯定是1,而后对于第i个,想让cnt/(i-1)尽量大就要想办法让cnt尽量大,那么就可以让前n-k个全为1,这是最优的,后面再依据前面的选数。


#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cmath>#include <set>#include <map>#include <algorithm>#include <vector>#include <stack>#include <queue>using namespace std;const int INF=0x3f3f3f3f;#define LL long longint cnt[100010];int ans[100010];int main(){    int n,k,p;    while(cin>>n>>k>>p)    {        memset(cnt,0,sizeof(cnt));        memset(ans,0,sizeof(ans));        cnt[1]=n-k;        LL res=n-k;        int cur=2;        int sum=cnt[1];        for(int i=n-k; i<n; i++)        {            if(sum*100<p*i)            {                cur++;                sum+=cnt[cur-1];            }            ans[i]=cur;            cnt[cur]++;            res+=cur;        }        printf("%lld\n",res);        for(int i=0; i<n-k; i++)            printf("%s1",!i?"":" ");        for(int i=n-k; i<n; i++)            printf(" %d",ans[i]);        printf("\n");    }    return 0;}

0 0
原创粉丝点击