HDU1871+水~~

View Code
 1 /*
 2 水~~~
 3 */
 4 #include<stdio.h>
 5 #include<string.h>
 6 #include<stdlib.h>
 7 #include<algorithm>
 8 #include<iostream>
 9 #include<queue>
10 #include<map>
11 #include<vector>
12 #include<math.h>
13 using namespace std;
14 typedef long long ll;
15 //typedef __int64 int64;
16 const int maxn = 105;
17 const int maxm = 1005;
18 const int inf = 0x7FFFFFFF;
19 const int CLEAR = 0x7F;
20 const double pi=acos(-1.0);
21 const double eps = 1e-8;
22 struct node{
23     int id,num,val;
24 };
25 node a[ maxn ];
26 int cmp( node a,node b ){
27     if( a.val!=b.val ) return a.val<b.val;
28     else return a.num<b.num;
29 }
30 int main(){
31     int ca;
32     scanf("%d",&ca);
33     while( ca-- ){
34         int num;
35         scanf("%d",&num);
36         for( int i=1;i<=num;i++ ){
37             scanf("%d%d%d",&a[i].id,&a[i].num,&a[i].val);
38         }
39         int num2,tt;
40         scanf("%d",&num2);
41         while( num2-- ){
42             scanf("%d",&tt);
43             int ans = inf;
44             int id;
45             int tmp;
46             for( int i=1;i<=num;i++ ){
47                 if( a[i].num>=tt ){
48                     if( ans>a[i].val ){
49                         ans = a[i].val;
50                         id=a[i].id;
51                         tmp = i;
52                     }
53                 }
54             }
55             if( ans!=inf ){
56                 a[ tmp ].num-=tt;
57                 printf("%d\n",id);
58             }
59             else{
60                 printf("sorry\n");
61             }
62         }
63     }
64     return 0;
65 }

 

posted @ 2013-04-04 14:07  xxx0624  阅读(291)  评论(0编辑  收藏  举报