您的位置:首页 > 其它

URAL 1995 Illegal spices 贪心构造

2017-03-20 20:24 417 查看
题目链接:这里

题意:

有n个物品,然后有k个东西留了下来

如果x/(i-1)

//URAL 1995

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n, k, p, a[maxn];
int main(){
scanf("%d%d%d", &n, &k, &p);
k = n-k;
int now = 1, num = 0;
for(int i = 1; i <= n; i++){
if(i <= k){
a[i] = 1;
num++;
}
else{
if(100*num >= p*(i-1)){
a[i] = now+1;
}
else{
now++;
num=i-1;
a[i] = now+1;
}
}
}
long long ans = 0;
for(int i = 1; i <= n; i++) ans += a[i];
printf("%lld\n", ans);
for(int i = 1; i <= n; i++){
printf("%d%c", a[i], i==n?'\n':' ');
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: