UVa, 10107 What is the Median?
来源:互联网 发布:淘宝拍摄培训班 编辑:程序博客网 时间:2024/05/16 05:55
The Problem
Median plays an important role in the world of statistics. By definition, it is a value which divides an array into two equal parts. In this problem you are to determine the current median of some long integers.Suppose, we have five numbers {1,3,6,2,7}. In this case, 3 is the median as it has exactly two numbers on its each side. {1,2} and {6,7}.
If there are even number of values like {1,3,6,2,7,8}, only one value cannot split this array into equal two parts, so we consider the average of the middle values {3,6}. Thus, the median will be (3+6)/2 = 4.5. In this problem, you have to print only the integer part, not the fractional. As a result, according to this problem, the median will be 4!
Input
The input file consists of series of integers X ( 0 <= X < 2^31 ) and total number of integers N is less than 10000. The numbers may have leading or trailing spaces.Output
For each input print the current value of the median.Sample Input
1346070502
Sample Output
12334274
#include <iostream> // std::cout#include <algorithm> // std::sort#include <vector> // std::vector#include <cstdio>using namespace std;int main(){ int num[10000]; int n,i,a,s=0; cin>>num[0]; cout<<num[0]<<endl; i=1; while(cin>>num[i]) { i++; sort(num,num+i); /*for(j=0;j<i;j++) { cout<<num[j]<<endl; }*/ // printf("**%d**",i); if(i%2!=0) cout<<num[(i-1)/2]<<endl; if(i%2==0) { s=(num[i/2]+num[i/2-1])/2; cout<<s<<endl; } } return 0;}
- Uva 10107 - What is the Median?
- UVa 10107 What is the Median?
- UVa, 10107 What is the Median?
- UVa 10107 - What is the Median?
- uva 10107 What is the Median?
- UVa10107 What is the Median?
- UVA10107 What is the Median?
- uva 10056 - What is the Probability ?
- UVA - 10056 What is the Probability ?
- UVa:10056 What is the Probability ?
- UVa 10056 — What is the Probability?
- uva 10056 What is the Probability ?
- What is the Probability - UVa 10056 概率
- UVA - 10056 What is the Probability ?
- UVa 10646 - What is the Card?
- UVA 10056 What is the Probability ?
- UVA - 10056 What is the Probability ? 概率UVA - 10056 What is the Probability ?
- UVa 10056 What is the Probability ? (概率&有一个陷阱)
- android studio设置
- (pojstep1.1.2)2654(直叙式模拟)
- 视频编解码学习之路(H264)
- UVa, 10041 Vito's Family UVa, 10041
- 文献类型和标志代码
- UVa, 10107 What is the Median?
- zoj3591 Nim
- 凸包问题 —— Graham扫描法
- UVa, 10327 Flip Sort
- vim tab键默认4空格
- Unity3D开发(三):场景管理插件Scene Manager
- Android Studio工程列表没有文件夹,如何恢复默认设置
- 分组交换
- UVa, 11000 Bee