首页 > 其他 > 详细

Noip2007提高组

时间:2019-10-26 20:40:39      阅读:100      评论:0      收藏:0      [点我收藏+]

2水题 + 1中等 + 1稍难


t1.统计数字

题目

题意:给定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;
}

t2.

Noip2007提高组

原文:https://www.cnblogs.com/Benjamin-cpp/p/11745332.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!