HDU 1871 无题

无题

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4042    Accepted Submission(s): 1713

Problem Description

就要复试了,外地的考生都要在学校附近住宾馆了。假设在学校附近有C家宾馆,并且这些宾馆只有单人房,而每家宾馆的价格不一样,学生们都想找价格便宜的住,所以现在需要你的帮助,当有学生需要住宾馆的时候,告诉他哪个宾馆还有空的房间并且价格最便宜。而且有一个要求,同一个组的学生要住在同一个宾馆。

Input

输入包括多组数据。输入首先包括一个整数T(T <= 50),代表有T组数据。
每组数据首先是一个整数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

2008浙大研究生复试热身赛(2)——全真模拟

Recommend

lcy   |   We have carefully selected several similar problems for you:  1873 1872 1876 2041 2153 

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<algorithm>
 5 using namespace std;
 6 struct Node{
 7     int bianhao,jiage,num;
 8     bool operator < (const Node &a) const{
 9         return jiage<a.jiage;
10     }
11 }e[110];
12 int T,n,m,x;
13 int main()
14 {
15     scanf("%d",&T);
16     while(T--){
17         memset(e,0,sizeof(e));
18         scanf("%d",&n);
19         for(int i=1;i<=n;i++){
20             scanf("%d%d%d",&e[i].bianhao,&e[i].num,&e[i].jiage);
21         }
22         sort(e+1,e+n+1);
23         scanf("%d",&m);
24         while(m--){
25             scanf("%d",&x);
26             int pos=-1;
27             for(int i=1;i<=n;i++){
28                 if(e[i].num>=x){
29                     e[i].num-=x;pos=e[i].bianhao;break;
30                 }
31             }
32             if(pos==-1)printf("sorry
");
33             else printf("%d
",pos);
34         }
35     }
36     return 0;
37 }

打眼一看数据暴力秒

原文地址:https://www.cnblogs.com/suishiguang/p/6378287.html