洛谷 P2073 送花

错误记录:21,32,41行goto写成continue导致没有读入x就continue了导致无限等待输入导致TLE

 1 #include<cstdio>
 2 #include<queue>
 3 #include<set>
 4 using namespace std;
 5 typedef pair<int,int> P;
 6 priority_queue<P> q1;
 7 priority_queue<P,vector<P>,greater<P> > q2;
 8 bool exist[1000100],inq[100100];
 9 int now,ans1,ans2;
10 int w[300100],c[300100];
11 int main()
12 {
13     int x,w1,c1,i;
14     P t;
15     scanf("%d",&x);
16     while(x!=-1)
17     {
18         if(x==1)
19         {
20             scanf("%d%d",&w1,&c1);
21             if(exist[c1])    goto xxx;
22             w[++now]=w1;
23             c[now]=c1;
24             q1.push(P(c1,now));
25             q2.push(P(c1,now));
26             inq[now]=1;
27             exist[c1]=1;
28         }
29         else if(x==2)
30         {
31             while(!q1.empty()&&!inq[q1.top().second])    q1.pop();
32             if(q1.empty())    goto xxx;
33             t=q1.top();
34             q1.pop();
35             inq[t.second]=0;
36             exist[c[t.second]]=0;
37         }
38         else
39         {
40             while(!q2.empty()&&!inq[q2.top().second])    q2.pop();
41             if(q2.empty())    goto xxx;
42             t=q2.top();
43             q2.pop();
44             inq[t.second]=0;
45             exist[c[t.second]]=0;
46         }
47         xxx:
48         scanf("%d",&x);
49     }
50     for(i=1;i<=now;i++)
51         if(inq[i])
52             ans1+=w[i],ans2+=c[i];
53     printf("%d %d",ans1,ans2);
54     return 0;
55 }
posted @ 2017-11-01 22:02  hehe_54321  阅读(155)  评论(0编辑  收藏  举报
AmazingCounters.com