HDU5437 Alisha's Party (priority queue + simulation)
Source 2015 ACM/ICPC Asia Regional Changchun Online question: k people bring a gift of value vi to open the door m times. Every time t people come, open the door and put in p people, when everyone came, they opened the door again to bring the rest of the people into the room. Every time there were people with high gift values, they came first with the same value. q times asked, ask the name of the nth incoming person.
Analysis: priority queue + simulation is acceptable, but note that m can be 0.
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include using namespace std;const double eps = 1e-6;const double pi = acos(-1.0);const int INF = 0x3f3f3f3f;const int MOD = 1000000007;#define ll long long#define CL(a,b) memset(a,b,sizeof(a))#define lson (i<<1)#define rson ((i<<1)|1)#define MAXN 150010struct node{ int id,v; char name[220]; bool operator < (const node &tmp) const { if(v == tmp.v) return id < tmp.id; return v > tmp.v; }}p[MAXN];struct opendoor{ int a,b; bool operator < (const opendoor &tmp) const { return a < tmp.a; }}od[MAXN];set
s;int query[110];int main(){ int T,n,m,q; scanf("%d",&T); while(T--) { s.clear(); scanf("%d%d%d",&n,&m,&q); for(int i=1; i<=n; i++) { scanf("%s %d",p[i].name, &p[i].v); p[i].id = i; } for(int i=0; i
ans; int cnt = 0; for(int i=1; i<=n&&ans.size()
id); s.erase(s.begin()); } cnt++; } } while(!s.empty() && ans.size()
id); s.erase(s.begin()); } for(int i=0; i