公主之魔镜魔镜 | ||||||
| ||||||
Description | ||||||
公主大病一场后变得很虚弱,总是感冒发烧什么的。公主的亲姐为了哄公主开心,就给了公主一个魔镜,并在魔镜中放了许多装有糖果的瓶子。魔镜是很神奇的,它有一个魔法就是能够以最快的速度把魔镜中装有最多糖的瓶子给公主,公主每次都吃 K 颗糖后就把糖瓶放回魔镜中。 | ||||||
Input | ||||||
输入数据有多组。 m (0 <= m <= 10000)以及公主每次吃 k (0 <= k <= 500)颗糖。 | ||||||
Output | ||||||
对于每组测试数据,输出 m 个整数并占一行,每个整数中间用一个空格隔开, 表示公主 m 次取糖过程中,每次魔镜给的装有最多糖的瓶子中糖的个数。 | ||||||
Sample Input | ||||||
10 6 3 15 7 3 12 8 6 9 5 4 8
| ||||||
Sample Output | ||||||
15 12 12 9 9 9 | ||||||
Hint | ||||||
公主慷慨的亲姐给了公主很多很多糖..而公主..是一个吃货..所以..魔镜得用一种尽可能快的方法来满足吃货公主的要求.. | ||||||
Author | ||||||
曾卓敏@Amber |
优先队列 排序 priority_queue<int ,vector<int >,less<int >>q;
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
int n,m,k;
while(~scanf("%d%d%d",&n,&m,&k))
{
int a;
priority_queue<int ,vector<int >,less<int >>q;
for(int i=0;i<n;i++)
{
scanf("%d",&a);
q.push(a);
}
while(m--)
{
int z=q.top();
printf("%d",z);
z-=k;
q.pop();
q.push(z);
if(m)
printf(" ");
else printf("\n");
}
}
}