poj2388-Who's in the Middle(排序)

水题:求中位数。

 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 int main(){
 5     int n;
 6     int arr[10010];
 7     cin>>n;
 8     for(int i = 0 ; i < n ; i++){
 9         cin>>arr[i];
10     }
11     sort(arr,arr+n);   //头文件:algorithm
12     cout<<arr[n/2]<<endl;
13     return 0;
14 }

版权声明:本文为博主原创文章,未经博主允许不得转载。

poj2388-Who's in the Middle(排序)

时间: 2024-10-09 02:11:57

poj2388-Who's in the Middle(排序)的相关文章

(hdu step 1.3.8)Who&#39;s in the Middle(排序)

题目: Who's in the Middle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2938 Accepted Submission(s): 1109   Problem Description FJ is surveying his herd to find the most average cow. He wants to k

STL 源码剖析 算法 stl_algo.h -- partial_sort / partial_sort_copy

本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie partial_sort / partial_sort_copy ----------------------------------------------------------------------------------------------------------------------------------------- 描述:本算法接受一个 middle 迭代器(位于序

poj2388(Who&#39;s in the Middle)

题目大意: 给你奇数个奶牛的产奶量,求产奶量的中位数. 解题思路. sort排序. 代码: 1 #include <algorithm> 2 #include <iostream> 3 #include <sstream> 4 #include <cstdlib> 5 #include <cstring> 6 #include <cstdio> 7 #include <string> 8 #include <bits

POJ 2388 Who&#39;s in the Middle(水~奇数个数排序求中位数)

题目链接:http://poj.org/problem?id=2388 题目大意: 奇数个数排序求中位数 解题思路:看代码吧! AC Code: 1 #include<stdio.h> 2 #include<algorithm> 3 using namespace std; 4 int main() 5 { 6 int n; 7 while(scanf("%d",&n)!=EOF) 8 { 9 int na[n+1]; 10 for(int i=0; i

poj2388解题报告(排序)

POJ 2388,题目链接http://poj.org/problem?id=2388 题意: 水题一道 给定n个数,输出中间值,可以用sort,干脆快捷. 代码: //396K 32MS #include <cstdio> #include <algorithm> int buf[10000]; int main() { int cowsNum; scanf("%d", &cowsNum); int temp; for (int i=0; i<c

简单排序poj2388

#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h> using namespace std;int cmp(const void *a,const void *b){ return *(int *)a-*(int *)b;}int main(){ int n; int a[10001]; while(scanf("%d",&n)!=

暑假集训(2)第五弹 ----- Who&#39;s in the Middle(poj2388)

G - Who's in the Middle Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'median

Who&#39;s in the Middle(简单排序)

训练计划第一题,先从水题开始:对数组进行排序,然后输出中间数. http://poj.org/problem?id=2388 冒泡排序: #include <iostream> using namespace std; int main() { int i, j, n,t; int a[10000]; cin>>n; for(i=0; i<n; i++) { cin>>a[i]; } //冒泡排序 for(i=0; i<n-1; i++) for(j=0;

HDU 1157 Who&#39;s in the Middle (快速排序 or 任意排序)

Who's in the Middle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9903    Accepted Submission(s): 4736 Problem Description FJ is surveying his herd to find the most average cow. He wants to k