无题
Problem Description
就要复试了,外地的考生都要在学校附近住宾馆了。假设在学校附近有C家宾馆,并且这些宾馆只有单人房,而每家宾馆的价格不一样,学生们都想找价格便宜的住,所以现在需要你的帮助,当有学生需要住宾馆的时候,告诉他哪个宾馆还有空的房间并且价格最便宜。而且有一个要求,同一个组的学生要住在同一个宾馆。
Input
输入包括多组数据。输入首先包括一个整数T(T <= 50),代表有T组数据。 每组数据首先是一个整数C(C <= 100),代表宾馆的个数,接下来是C行数据,每行3个整数,第一个代表宾馆的编号(<=1000),第二个是宾馆的房间数(<=50),第三个是宾馆的价格(<=1000)。 然后是一个整数T (T <= 1000),代表想找宾馆住的小组,接下来的T行每行代表一个要找宾馆的小组,每个小组不超过10人。
Output
对于每组数据中的想找宾馆的小组,输出他们应该找的宾馆编号。如果没有合适的宾馆或已经住满,输出”sorry”.
#include<iostream>
#include<queue>
using namespace std;
class h
{
public:
int ord;
int room;
int price;
friend bool operator<(h &a,h&b);
};
bool operator<(const h &a,const h &b)
{
return b.price<a.price;
}
int main()
{
int T,C,t,p;
h hotel;
h num[105];
int j,i,k,flag;
cin>>T;
priority_queue<h>qu;
while(T--)
{
while(!qu.empty())
qu.pop();
cin>>C;
j=0;
flag=0;
for(i=0;i<C;++i)
{
cin>>hotel.ord>>hotel.room>>hotel.price;
qu.push(hotel);
}
while(!qu.empty())
{
num[j++]=qu.top();
qu.pop();
}
cin>>t;
while(t--)
{
flag=0;
cin>>p;
for(i=0;i<C;++i)
{
if(num[i].room>=p)
{
cout<<num[i].ord<<endl;
num[i].room-=p;
flag=1;
break;
}
}
if(flag==0)
cout<<"sorry"<<endl;
}
}
}
#include<queue>
using namespace std;
class h
{
public:
int ord;
int room;
int price;
friend bool operator<(h &a,h&b);
};
bool operator<(const h &a,const h &b)
{
return b.price<a.price;
}
int main()
{
int T,C,t,p;
h hotel;
h num[105];
int j,i,k,flag;
cin>>T;
priority_queue<h>qu;
while(T--)
{
while(!qu.empty())
qu.pop();
cin>>C;
j=0;
flag=0;
for(i=0;i<C;++i)
{
cin>>hotel.ord>>hotel.room>>hotel.price;
qu.push(hotel);
}
while(!qu.empty())
{
num[j++]=qu.top();
qu.pop();
}
cin>>t;
while(t--)
{
flag=0;
cin>>p;
for(i=0;i<C;++i)
{
if(num[i].room>=p)
{
cout<<num[i].ord<<endl;
num[i].room-=p;
flag=1;
break;
}
}
if(flag==0)
cout<<"sorry"<<endl;
}
}
}
浙公网安备 33010602011771号