无题
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1303 Accepted Submission(s): 565
Problem Description
就要复试了,外地的考生都要在学校附近住宾馆了。假设在学校附近有C家宾馆,并且这些宾馆只有单人房,而每家宾馆的价格不一样,学生们都想找价格便宜的住,所以现在需要你的帮助,当有学生需要住宾馆的时候,告诉他哪个宾馆还有空的房间并且价格最便宜。而且有一个要求,同一个组的学生要住在同一个宾馆。
Input
输入包括多组数据。输入首先包括一个整数T(T <= 50),代表有T组数据。
每组数据首先是一个整数C(C <= 100),代表宾馆的个数,接下来是C行数据,每行3个整数,第一个代表宾馆的编号(<=1000),第二个是宾馆的房间数(<=50),第三个是宾馆的价格(<=1000)。
然后是一个整数T (T <= 1000),代表想找宾馆住的小组,接下来的T行每行代表一个要找宾馆的小组,每个小组不超过10人。
每组数据首先是一个整数C(C <= 100),代表宾馆的个数,接下来是C行数据,每行3个整数,第一个代表宾馆的编号(<=1000),第二个是宾馆的房间数(<=50),第三个是宾馆的价格(<=1000)。
然后是一个整数T (T <= 1000),代表想找宾馆住的小组,接下来的T行每行代表一个要找宾馆的小组,每个小组不超过10人。
Output
对于每组数据中的想找宾馆的小组,输出他们应该找的宾馆编号。如果没有合适的宾馆或已经住满,输出”sorry”.
Sample Input
1 2 1 2 100 2 3 120 4 3 1 1 5
Sample Output
2 1 1 sorry
Author
8600
Source
Recommend
lcy
开始在一个小地方卡了一下,就是那里要不要根据宾馆的编号定位数组,而题目中未说明宾馆编号有序,所以还是该分量还是包括在结构体里面比较好,另外所有的小组选择房间的标准时一样的,所以只要一开始根据价格排序依次就可以了,后面只需修改剩余房间数就可以了
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <string>
#include <algorithm>
using namespace std;
struct node
{
int no;//编号无规律,还是用结点比较好
int remain;
int price;
};
{
int no;//编号无规律,还是用结点比较好
int remain;
int price;
};
int cmp(node x,node y)
{
return x.price<y.price;
}
node hotel[1002];
{
return x.price<y.price;
}
node hotel[1002];
int main()
{
int t;
cin>>t;
int n;
while(t--)
{
cin>>n;
int top=-1;
node temp;
for(int i=0;i<n;i++)
{
cin>>temp.no>>temp.remain>>temp.price;
hotel[++top]=temp;
}
sort(hotel,hotel+top+1,cmp);
{
int t;
cin>>t;
int n;
while(t--)
{
cin>>n;
int top=-1;
node temp;
for(int i=0;i<n;i++)
{
cin>>temp.no>>temp.remain>>temp.price;
hotel[++top]=temp;
}
sort(hotel,hotel+top+1,cmp);
int m;
cin>>m;
while(m--)
{
int require;
cin>>require;
for(int i=0;i<=top;i++)
if(hotel[i].remain>=require)
{
cout<<hotel[i].no<<endl;
hotel[i].remain-=require;
break;
}
if(i==top+1)cout<<"sorry"<<endl;
}
cin>>m;
while(m--)
{
int require;
cin>>require;
for(int i=0;i<=top;i++)
if(hotel[i].remain>=require)
{
cout<<hotel[i].no<<endl;
hotel[i].remain-=require;
break;
}
if(i==top+1)cout<<"sorry"<<endl;
}
}
return 0;
}
return 0;
}