Gym 101102C Bored Judge(set--结构体集合)
Posted icode-xiaohu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Gym 101102C Bored Judge(set--结构体集合)相关的知识,希望对你有一定的参考价值。
这个故事告诉我们,WA了一定要找自己的原因... ...
当我开始用set去做的时候,发现一直过不去,一开始忘了把初始排名加进去,后来忘了第0秒,第0秒第一的id = 1
这个题目的做法也不只这一种,应该说这一种是最偷懒的.
代码如下:
#include<iostream> #include<cstring> #include<cstdio> #include<set> using namespace std; #define N 100005 int s[N],win[N]; struct Node { int id,sc; Node(int i=0,int s=0) { id = i; sc = s; } bool operator < (Node A) const { if(A.sc != sc) return sc > A.sc; else return id < A.id; } }; set<Node> st; set<Node>::iterator it; int main() { // freopen("C.in.cpp","r",stdin); int T,n,q,x,p; scanf("%d",&T); while(T--) { st.clear(); memset(s,0,sizeof(s)); scanf("%d%d",&n,&q); for(int i = 1; i <= n; i++) { st.insert(Node(i,0)); } win[0] = 1; for(int i = 1; i <= q; i++) { scanf("%d%d",&x,&p); st.erase(Node(x,s[x])); s[x] += p; st.insert(Node(x,s[x])); it = st.begin(); Node tmp = *it; win[i] = (*it).id; } int i; for(i = q; i >= 1; i--) { if(win[i] != win[i-1]) { break; } } printf("%d\n",i); } return 0; }
以上是关于Gym 101102C Bored Judge(set--结构体集合)的主要内容,如果未能解决你的问题,请参考以下文章
“What a boring world!” Julyed felt so bored that she began to write numbers on the coordinate paper.
1075 PAT Judge (25point(s)) Easy twice agin *一些细节问题