首先题意分析···
题意很明白,首先要求是要便宜,其次是这个宾馆可以装下这组所有的人 QAQ 这题里面没有任何的坑 所以只要放心大胆的写就好了(趴
接着上代码
<span style="font-family:SimHei;font-size:18px;">#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;
typedef struct {
int no;
int room;
int worth;
}Node;
bool cmp(Node a,Node b)
{
return a.worth<b.worth;
}
Node node[1005];
int res[1005];
int main(){
int t;
scanf("%d",&t);
while(t--){
int c;
scanf("%d",&c);
int i;
for (i=0;i<c;i++)
{
scanf("%d %d %d",&node[i].no,&node[i].room,&node[i].worth);
}
int s;
scanf("%d",&s);
int stu[1005];
for (i=0;i<s;i++)
scanf("%d",&stu[i]);
sort(node,node+c,cmp);
for (i=0;i<s;i++)
{
for (int j=0;j<c;j++)
{
if (stu[i]>node[j].room)
res[i]=-1;
else
{
res[i]=node[j].no;
node[j].room-=stu[i];
break;
}
}
}
for (i=0;i<s;i++)
if (res[i]==-1)
printf("sorry\n");
else
printf("%d\n",res[i]);
}
return 0;
}
</span>
这个是当时做题的时候差不多的代码 跟最后ac的代码的差别就是··· 我把那node的数组和res的数组定义在循环里了··然后就错了 我很费解啊(´Д`)
所以求指教