選機房
Input
文件第一行:一個正整數t<=20表示測試數據的組數。
接下來t行表示t組數據,每組數據按照以下格式:
第一行兩個正整數n<=100000和k<=1000以空格隔開,表示參賽隊的總數和可以選擇的機房總數k。
接下來k行每行一個正整數c<=20000。
第1行表示1號機房所能容納的隊伍總數,第2行表示2號機房能容納的隊伍數,以此類推,已知所有k個機房的大小均不相同,並且所有機房的總容量大於n。
Output
Sample Input
2 200 2 300 400 100 5 50 4 20 40 5
Sample Output
2 1 3 4
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
struct node
{
int c,flag;
bool operator < (const node &b) const
{
return c<b.c;
}
}a[1010];
int mark[1010];
priority_queue<node>pq;
int main()
{
int test;
int n,k,i,j;
node temp;
cin>>test;
while(test--)
{
j=0;
memset(mark,0,sizeof(mark));
cin>>n>>k;
for(i=0;i<k;i++)
{
cin>>a[i].c;
a[i].flag=i+1;
pq.push(a[i]);
}
temp=pq.top();
pq.pop();
mark[j++]=temp.flag;
while(n-temp.c>=0)
{
n-=temp.c;
temp=pq.top();
pq.pop();
mark[j++]=temp.flag;
}
while(!pq.empty())
{
pq.pop();
}
sort(mark,mark+j);
for(i=0;i<j;i++)
{
cout<<mark[i]<<endl;
}
cout<<endl;
}
return 0;
}