标签:har queue int i++ sky 题意 cst priority line
2水题 + 1中等 + 1稍难
题意:给定n个数,按数字从小到大的顺序输出数字及出现次数。
思路:[水题]爱怎么搞怎么搞,反正我就是要用优先队列。
Code:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
//Mystery_Sky
//
#define INF 0x3f3f3f3f
#define M 1000100
#define ll long long
inline int read()
{
int x=0,f=1; char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
}
int n;
struct node{
int x;
inline bool operator <(const node& a) const{
return a.x < x;
}
};
priority_queue <node> Q;
int main() {
n = read();
for(int i = 1; i <= n; i++) {
int x = read();
Q.push((node){x});
}
node last = Q.top();
Q.pop();
int count = 1;
while(!Q.empty()) {
node top = Q.top();
Q.pop();
if(top.x == last.x) count++;
else {
printf("%d %d\n", last.x, count);
count = 1;
last = top;
}
//printf("->%d %d<-\n", top.x, count);
}
printf("%d %d\n", last.x, count);
return 0;
}
标签:har queue int i++ sky 题意 cst priority line
原文地址:https://www.cnblogs.com/Benjamin-cpp/p/11745332.html