前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >P1168 中位数

P1168 中位数

作者头像
attack
发布2018-04-13 11:03:21
9170
发布2018-04-13 11:03:21
举报

题目描述

给出一个长度为N的非负整数序列A[i],对于所有1 ≤ k ≤ (N + 1) / 2,输出A[1], A[3], …, A[2k - 1]的中位数。[color=red]即[/color]前1,3,5,……个数的中位数。

输入输出格式

输入格式:

输入文件median.in的第1行为一个正整数N,表示了序列长度。

第2行包含N个非负整数A[i] (A[i] ≤ 10^9)。

输出格式:

输出文件median.out包含(N + 1) / 2行,第i行为A[1], A[3], …, A[2i – 1]的中位数。

输入输出样例

输入样例#1:

7
1 3 5 7 9 11 6

输出样例#1:

1
3
5
6

说明

对于20%的数据,N ≤ 100;

对于40%的数据,N ≤ 3000;

对于100%的数据,N ≤ 100000。

编译都不过居然能AC

虽然也不知道怎么AC的。。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<ext/pb_ds/assoc_container.hpp>
 6 #include<ext/pb_ds/tree_policy.hpp>
 7 #include<functional>
 8 using namespace std;
 9 using namespace __gnu_pbds;
10 void read(int & n)
11 {
12     char c='+';int x=0;int flag=0;
13     while(c<'0'||c>'9')
14     {    c=getchar();    if(c=='-')    flag=1;    }
15     while(c>='0'&&c<='9')
16     {x=x*10+(c-48);c=getchar();}
17     flag==1?n=-x:n=x;
18 }
19 int main()
20 {
21     int n;int p;
22     read(n);
23     //tree<int , null_type , less_equal<int> , rb_tree_tag , tree_order_statistics_node_update>t;
24     tree<int, null_type, std::less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> t;
25     for(int i=1;i<=n;i++)
26     {
27         read(p);
28         t.insert(p);
29         if(i%2==1)
30         printf("%d\n", *t.find_by_order(i / 2 ));
31     }
32     return 0;
33 }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-06-27 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题目描述
  • 输入输出格式
  • 输入输出样例
  • 说明
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档