• 这个OJ一直在做,一些专题题目都很好,从易至难,阶梯上升,很适合像我这样的蒟蒻 =7=
  • 这篇是关于其中一个专题训练的题解思路及代码   http://120.78.128.11/Contest.jsp?cid=486
  • 所有题面我就不贴了,各位自行去看,链接在上一行 =7=

 

  • 其实数组维护也可以做,但既然是STL训练,就用STL的东西了
  • 用map标记数据和出现的次数,然后转入结构体存入map中
  • 为什么不直接用set<map<T,T> >的形式 是因为map只能对关键字排序,而我们需要排次数,所以存入set中先转存入结构体
  • 然后没啥坑点,结构体自己构造一个排序就行了,如何构造请看另一篇博文
  • 代码:
 1 #include <iostream>
 2 #include <string>
 3 #include <cstdio>
 4 #include <cstdlib>
 5 #include <sstream>
 6 #include <iomanip>
 7 #include <map>
 8 #include <stack>
 9 #include <deque>
10 #include <queue>
11 #include <vector>
12 #include <set>
13 #include <list>
14 #include <cstring>
15 #include <cctype>
16 #include <algorithm>
17 #include <iterator>
18 #include <cmath>
19 #include <bitset>
20 #include <ctime>
21 #include <fstream>
22 #include <limits.h>
23 #include <numeric>
24 
25 using namespace std;
26 
27 #define F first
28 #define S second
29 #define mian main
30 #define ture true
31 
32 #define MAXN 1000000+5
33 #define MOD 1000000007
34 #define PI (acos(-1.0))
35 #define EPS 1e-6
36 #define MMT(s) memset(s, 0, sizeof s)
37 typedef unsigned long long ull;
38 typedef long long ll;
39 typedef double db;
40 typedef long double ldb;
41 typedef stringstream sstm;
42 const int INF = 0x3f3f3f3f;
43 
44 struct node{
45     int sum,x;
46     bool operator <(const node &b)const{
47         if(sum == b.sum)
48             return x < b.x;
49         else
50             return sum > b.sum;
51     }
52 };
53 
54 map<int,int >q;
55 set<node>p;
56 set<node>::iterator it;
57 
58 int main(){
59     ios_base::sync_with_stdio(false);
60     cout.tie(0);
61     cin.tie(0);
62     int n,t,x,d,e;
63     while(~scanf("%d",&n)){
64         q.clear();
65         p.clear();
66         while(n--){
67             scanf("%d",&t);
68             if(t == 1){
69                 scanf("%d",&x);
70                 q[x]++;
71                 p.insert((node){q[x],x});
72             }
73             else{
74                 if(!p.empty()){
75                     e = p.begin()->sum;
76                     int flag = 0;
77                     for(it = p.begin(); it != p.end(); it++){
78                         if(it->sum == e){
79                             if(flag++)
80                                 printf(" ");
81                             printf("%d",it->x);
82                         }
83                         else
84                             break;
85                     }
86                     puts("");
87                 }
88             }
89 
90         }
91     }
92 }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2021-09-13
  • 2021-06-26
  • 2021-05-24
  • 2021-11-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-21
  • 2021-08-29
  • 2022-01-12
相关资源
相似解决方案