九度oj1004
来源:互联网 发布:淘宝客联盟 编辑:程序博客网 时间:2024/05/16 23:57
- 题目描述:
Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1={11, 12, 13, 14} is 12, and the median of S2={9, 10, 15, 16, 17} is 15. The median of two sequences is defined to be the median of the non-decreasing sequence which contains all the elements of both sequences. For example, the median of S1 and S2 is 13.
Given two increasing sequences of integers, you are asked to find their median.
- 输入:
Each input file may contain more than one test case.
Each case occupies 2 lines, each gives the information of a sequence. For each sequence, the first positive integer N (≤1000000) is the size of that sequence. Then N integers follow, separated by a space.
It is guaranteed that all the integers are in the range of long int.
- 输出:
For each test case you should output the median of the two given sequences in a line.
- 样例输入:
4 11 12 13 145 9 10 15 16 17
- 样例输出:
13
#include<stdio.h>#include<stdlib.h>void quick_sort(long int a[],long int l,long int r){if(l<r){long int i,j,x;i=l;j=r;x=a[i];while(i<j){while(i<j&&a[j]>x)j--;if(i<j)a[i++]=a[j];while(i<j&&a[i]<x)i++;if(i<j)a[j--]=a[i];}a[i]=x;quick_sort(a,l,i-1);quick_sort(a,i+1,r);}}long int we[2000005]; long int i,j,a,b,c; int main(){ while(scanf("%d",&a)!=EOF) { for(i=0;i<a;i++) { scanf("%d",&we[i]); } scanf("%d",&b); for(j=a;j<a+b;j++) { scanf("%d",&we[j]); } c=a+b; long int x=c/2-1,y=c/2; quick_sort(we,0,c-1); if(c%2==0) { printf("%d\n",we[x]); } if(c%2==1) { printf("%d\n",we[y]); } } }
- 九度oj1004
- 九度OJ1004 Median
- 九度oj1004
- 九度oj1004题
- oj1004
- 九度oj1004 A+B 给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开
- 东秦oj1004
- 北大OJ1004
- [Java]杭电oj1004
- 百炼OJ1004
- 杭电oj1004
- Let the Balloon Rise(HDU OJ1004)
- 杭电oj1004最流行的气球颜色
- 【九度OJ】:九度OJ 1050
- 【九度OJ】:九度OJ 1053
- 【九度OJ】:九度OJ 1056
- 【九度OJ】:九度OJ 1059
- 【九度OJ】:九度OJ 1206
- 6.5-6
- 每天一个Linux命令-3( ls和 ll )
- 待解决和深究问题
- Spring整合JAX-WS
- 去美国之前
- 九度oj1004
- SQL server
- Bigram分词中的等效词串
- TOJ 3852 Haitang1 三维树状数组
- PAT 08-排序3. Talent and Virtue
- mysql,mysqli和PDO的区别
- 抽象类与接口的区别
- Scala中的继承:超类的构造、重写字段、重写方法
- ORA-00054: 资源正忙, 但指定以 NOWAIT 方式获取资源