hdu 1157 Who's in the Middle (水题,中位数)
2014-04-08 19:23
507 查看
小记:GNU C++硬是要我把变量都定义到main()函数外才能让我AC...
思路:读入数据存入数组,排序,输出中间那个,输入保证是奇数个。从0开始存,答案就是排好序后的第n/2个
代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
#define mst(a,b) memset(a,b,sizeof(a))
#define eps 10e-8
const int MAX_ = 10010;
int p[MAX_], n;
int main(){
while(~scanf("%d",&n)){
for(int i = 0; i < n; ++i){
scanf("%d",&p[i]);
}
sort(p,p+n);
printf("%d\n",p[n/2]);
}
return 0;
}
思路:读入数据存入数组,排序,输出中间那个,输入保证是奇数个。从0开始存,答案就是排好序后的第n/2个
代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
#define mst(a,b) memset(a,b,sizeof(a))
#define eps 10e-8
const int MAX_ = 10010;
int p[MAX_], n;
int main(){
while(~scanf("%d",&n)){
for(int i = 0; i < n; ++i){
scanf("%d",&p[i]);
}
sort(p,p+n);
printf("%d\n",p[n/2]);
}
return 0;
}
相关文章推荐
- HDU 1157 POJ 2388 Who's in the Middle 求中位数
- HDU 1157 Who's in the Middle
- 杭电 HDU 1157 Who's in the Middle
- HDU 1157 Who's in the Middle (快速排序 or 任意排序)
- HDU 1157 Who's in the Middle
- HDU 1157 Who's in the Middle
- HDU 1157 Who's in the Middle
- hdu 1157 Who's in the Middle
- 文章标题 HDU 1157 : Who's in the Middle(水)
- HDU-1157-Who's in the Middle
- HDOJ 1157 HDU 1157 Who's in the Middle ACM 1157 IN HDU
- HDU 1157 Who's in the Middle(排序取中间值)
- HDU 1157(Who's in the Middle) 快速排序
- HDU 1157 Who's in the Middle
- hdu 1157 (1.3.7) Who's in the Middle
- HDU 1157 Who's in the Middle 排序
- hdu-oj 1157 Who's in the Middle
- HDU 1157 Who's in the Middle
- HDU 1157 Who's in the Middle
- HDU 1157 Who's in the Middle