Max Kingdom

Problem Description

Max is the king of the universe, he rules billions of planets. In each planet, there may be several residents. Residents of Max's kingdom will never die, so some of them may be as old as the universe (It is a magic world, isn't it?). One day, Max wants to know how intellegent his people are so that he collects the intellegence information of all residents throughout universe. The intellegence can be presented by integer under a standard decided by Max. (That means, if the intellegence of resident Bob is presented as 10000, Bob is much more intellgent than the stadard. And if Max's intellegence number is 0, Max is as intellegent as the standard.) Actually, Max just cares how intellegent each planet is. To decide the intellegent degree of one planet, Max will take the middle one from all intellegent numbers of that planet and make it as the criteria. Here is the method to pick up the middle one: Supposed there are n residents in planet i. The intellegence of them are a1, a2, …, an (a1 ≤ a2 ≤ a3 ≤ … ≤ an). If n is odd, then the middle one is a[(n+1)/2], otherwise, middle one equals (a[n/2] + a[n/2 + 1]) / 2 (Here character / means integer division, e.g. 3 / 2 = 1, 4 / 2 = 2). Since there are too many residents to process, now is your task to tell Max how smart his people are.

Input

Input contains multiple test data sets. For each data set, there is one integer, n ( 1 <= n <= 1000000) the number of residents, in first line. Then comes n lines, each line i has two integers: p, a ( 1 ≤ p < 1.5 × 10^9, |a| ≤ 1.5 × 10^9) which means that resident i comes from planet p and his/her intellegent number is a. Input is terminated by EOF.

Output

For each test data set, one output data set should be generated as follow For each planet p appears in the test data set, output one line presenting two integers: p which is the planet identifier from input and the middle one number described as above. Output data set should be sorted by planet identifier in ascending order.

Sample Input

3
2 10
1 5
2 15
2
1 2
3 4

Sample Output

1 5
2 12
1 2
3 4
题意:给出第一个数n然后是n组两个数。第一个数代表星球第二个数代表该星球的人的智商。输出每个星球的平均智商
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
#define ll __int64
struct lmx{
    ll pos;
ll val;
};
bool is(lmx s ,lmx t)
{
    if(s.pos!=t.pos)  return s.pos<t.pos;
    else return s.val<t.val;
}
lmx lm[1000005],f;
int main()
{
    ll n,i,x,y,s;
    while(scanf("%I64d",&n)!=EOF)
    {
        for(i=0;i<n;i++)
        {
            scanf("%I64d%I64d",&lm[i].pos,&lm[i].val);
        }
        sort(lm,lm+n,is);
        lm[n].pos=0;
        lm[n].val=0;
        f=lm[0];
        s=0;
        for(i=1;i<=n;i++)
        {
            if(lm[i].pos!=f.pos)
            {
                if((i-s)&1)
                printf("%I64d %I64d\n",lm[i-1].pos,lm[(s+i-1)/2].val);
                else printf("%I64d %I64d\n",lm[i-1].pos,(lm[(s+i-1)/2].val+lm[(s+i)/2].val)/2);
                s=i;
                f=lm[i];
            }
        }
    }
}

转载于:https://www.cnblogs.com/ffhuguang/archive/2013/06/06/3120322.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值