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
 1 #include <stdio.h>
 2 #include <algorithm>
 3 #include <iostream>
 4 using namespace std;
 5 typedef long long ll;
 6 struct pa {
 7     int id;
 8     ll num;
 9 } t[1000005];
10 bool cmp(pa a,pa b) {
11     if(a.id!=b.id) return a.id<b.id;
12     else return a.num<b.num;
13 }
14 
15 int main() {
16     int n,i;
17     while(scanf("%d",&n)!=EOF) {
18         for(i=0; i<n; i++) scanf("%d %I64d",&t[i].id,&t[i].num);
19         sort(t,t+n,cmp);
20         int k=1,start=0;
21         t[n].id=-1,t[n].num=-1;
22         for(i=0; i<n; i++) {
23             if(t[i].id!=t[i+1].id){
24                 if(k%2==0) printf("%d %I64d\n",t[i].id,(t[(i+start)/2].num+t[(i+start)/2+1].num)/2);
25                 else printf("%d %I64d\n",t[i].id,t[(i+start)/2].num);
26                 k=1;
27                 start=i+1;
28             }
29             else k++;
30         }
31     }
32     return 0;
33 }
View Code

 

转载于:https://www.cnblogs.com/contestant/archive/2013/06/03/3115852.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值