您的位置:首页 > 其它

HDU 4557 非诚勿扰

2013-11-10 17:58 204 查看
水题,我直接暴力查询的,稍微有点优化就好了。

#include<stdio.h>
#include<iostream>
using namespace std;

#include<math.h>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<string>
#include<queue>

#define repA(p,q,i)  for( int (i)=(p); (i)!=(q); ++(i) )
#define repAE(p,q,i)  for( int (i)=(p); (i)<=(q); ++(i) )
#define repD(p,q,i)  for( int (i)=(p); (i)!=(q); --(i) )
#define repDE(p,q,i)  for( int (i)=(p); (i)>=(q); --(i) )
#define range 1010

char ope[10];
char name[range][20];
int ab[25][range];
bool confirm[range];

int total;
int query(int abl);

int main()
{
int test;  scanf("%d",&test);
int n, abl, ID;
repAE(1,test,round)
{
printf("Case #%d:\n",round);
scanf("%d",&n);
memset(confirm, 0 ,sizeof(confirm) );
repA(0,25,i)
ab[i][0]=1;

ID=total=0;

while(n--)
{
scanf("%s",ope);
if( strcmp(ope, "Add") == 0 )
{
scanf("%s",name[ID]);
scanf("%d",&abl);
ab[ abl ][ ab[abl][0]++ ] = ID;
++total;  ++ID;
printf("%d\n",total);
}

else
{
scanf("%d",&abl);
int here = query(abl);
if(here == -1)
printf("WAIT...\n");
else printf("%s\n",name[here]);

}
}
}
return 0;
}

int query(int abl)
{
if(total == 0)  return -1;
if(abl > 20 )  return -1;
repAE(abl,20,i)
{
repA(1, ab[ i ][ 0 ], j)
{
if( !confirm[ ab[i][j] ] )
{
confirm[ab[i][j] ] = true;
--total;
return ab[i][j] ;
}
}
}

return -1;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: