HDU 4557 非诚勿扰

水题,我直接暴力查询的,稍微有点优化就好了。

 1 #include<stdio.h>
 2 #include<iostream>
 3 using namespace std;
 4 
 5 #include<math.h>
 6 #include<algorithm>
 7 #include<string.h>
 8 #include<stdlib.h>
 9 #include<vector>
10 #include<set>
11 #include<map>
12 #include<stack>
13 #include<string>
14 #include<queue>
15 
16 #define repA(p,q,i)  for( int (i)=(p); (i)!=(q); ++(i) )
17 #define repAE(p,q,i)  for( int (i)=(p); (i)<=(q); ++(i) )
18 #define repD(p,q,i)  for( int (i)=(p); (i)!=(q); --(i) )
19 #define repDE(p,q,i)  for( int (i)=(p); (i)>=(q); --(i) )
20 #define range 1010
21 
22 char ope[10];
23 char name[range][20];
24 int ab[25][range];
25 bool confirm[range];
26 
27 int total;
28 int query(int abl);
29 
30 int main()
31 {
32     int test;  scanf("%d",&test);
33     int n, abl, ID;
34     repAE(1,test,round)
35     {
36         printf("Case #%d:\n",round);
37         scanf("%d",&n);
38         memset(confirm, 0 ,sizeof(confirm) );
39         repA(0,25,i)
40           ab[i][0]=1;
41 
42         ID=total=0;
43     
44         while(n--)
45         {
46             scanf("%s",ope);
47             if( strcmp(ope, "Add") == 0 )
48             {
49                 scanf("%s",name[ID]);
50                 scanf("%d",&abl);
51                 ab[ abl ][ ab[abl][0]++ ] = ID;
52                 ++total;  ++ID;
53                 printf("%d\n",total);
54             }
55 
56             else
57             {
58                 scanf("%d",&abl);
59                 int here = query(abl);
60                 if(here == -1)
61                   printf("WAIT...\n");
62                 else printf("%s\n",name[here]);
63 
64             }
65         }
66     }
67     return 0;
68 }
69 
70 int query(int abl)
71 {
72     if(total == 0)  return -1;
73     if(abl > 20 )  return -1;
74     repAE(abl,20,i)
75     {
76         repA(1, ab[ i ][ 0 ], j)
77         {
78             if( !confirm[ ab[i][j] ] )
79             {
80                 confirm[ab[i][j] ] = true;
81                 --total;
82                 return ab[i][j] ;
83             }
84         }
85     }
86 
87     return -1;
88 }
View Code

 

posted on 2013-11-10 17:58  码农之上~  阅读(218)  评论(0编辑  收藏  举报

导航