题目链接:
HDU:http://acm.hdu.edu.cn/showproblem.php?pid=3303
5 B 1 A 5 B 10 A 5 A 40 2 B 1 A 2 0
Case 1: 1 2 1 Case 2: 1
题意:
就是对一个集合,有两种操作:
1、将某个元素加入集合中;
2、一个是问当前集合中mod y 最小的数,如果有多个,输出最后加入的那个元素,要求的是输出他们加入集合的时间。
代码如下:
(不过此代码在POJ3145上会TLE,大概是由于HDU上的数据比较弱吧,所以就被我无耻的水过去了,等有时间再试试线段树吧!正确解法应该是用线段树)
//#pragma warning (disable:4786)
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <climits>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <deque>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
const double eps = 1e-9;
//const double pi = atan(1.0)*4;
const double pi = 3.1415926535897932384626;
#define INF 1e18
//typedef long long LL;
//typedef __int64 LL;
int a[5000017], b[5000017];
int main()
{
char cc[7];
int t, tt;
int cas = 0;
int cont = 0;
while(scanf("%d",&t) && t)
{
int l = 0;
if(cont)
printf("\n");
cont++;
printf("Case %d:\n",++cas);
while(t--)
{
scanf("%s%d",cc,&tt);
if(cc[0] == 'B')
{
a[l++] = tt;
}
else if(cc[0] == 'A')
{
int flag = 1;
int minn = tt, f = 0;
for(int i = 0; i < l; i++)
{
if(a[i]%tt <= minn)
{
flag = 0;
minn = a[i]%tt;
f = i+1;
}
}
if(flag)
{
printf("-1\n");
}
else
printf("%d\n",f);
}
}
// printf("\n");
}
return 0;
}
原文地址:http://blog.csdn.net/u012860063/article/details/39552917