uva 10057 A mid-summer night’s dream(中位数)
来源:互联网 发布:淘宝一千零一夜第二季 编辑:程序博客网 时间:2024/05/21 22:24
uva 10057 A mid-summer night’s dream
(|X1-A| + |X2-A| + … … + |Xn-A|) is minimum.
Input
Input will contain several blocks. Each block will start with a number n (0<n<=1000000) indicating how many numbers he saw in the dream. Next there will be n numbers. All the numbers will be less than 65536. The input will be terminated by end of file.
Output
For each set of input there will be one line of output. That line will contain the minimum possible value for A. Next it will contain how many numbers are there in the input that satisfy the property of A (The summation of absolute deviation from A is minimum). And finally you have to print how many possible different integer values are there for A (these values need not be present in the input). These numbers will be separated by single space.
Sample Input:
2
10
10
4
1
2
2
4
Sample Output:
10 2 1
2 2 1
题目大意:仲夏夜之梦!?一定是个高端大气的题目……题目要求求出最小的A,和n个数中可以满足A的个数,以及可以满足A的整数个数。
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>using namespace std;int num[10000005];int main() {int n;while (scanf("%d", &n) == 1) {for (int i = 0; i < n; i++) {scanf("%d", &num[i]);}sort(num, num + n);int cnt = 0;if (n % 2) {for (int i = 0; i < n; i++) {if (num[i] == num[n / 2]) cnt++;}printf("%d %d 1\n", num[n / 2], cnt);} else {for (int i = 0; i < n; i++) {if (num[i] == num[n / 2] || num[i] == num[(n / 2) - 1]) cnt++;}printf("%d %d %d\n", num[(n / 2) - 1], cnt, num[n / 2] - num[(n / 2) - 1] + 1);}}return 0;}
0 0
- uva 10057 A mid-summer night’s dream(中位数)
- UVA - 10057 A mid-summer night's dream. 求中位数
- A mid-summer night’s dream - UVa 10057 中位数
- UVA A mid-summer night’s dream(中位数求值)
- uva - 10057 - A mid-summer night's dream. (数学、中位数)
- UVA - 10057 - A mid-summer night's dream. (找中位数!)
- A mid-summer night’s dream uva+二分/中位数
- uva 10057 A mid-summer night's dream.(检索)
- UVA 10057 A mid-summer night's dream. 仲夏夜之梦 求中位数
- UVa 10057 A mid-summer night's dream. (二分&可以取哪些作为中位数?)
- UVa 10057 - A mid-summer night's dream.
- uva 10057 - A mid-summer night's dream.
- uva 10057 - A mid-summer night's dream.
- UVa 10057 - A mid-summer night's dream.
- UVa 10057 - A mid-summer night's dream.
- UVA 10057 - A mid-summer night's dream.
- uva 10057 - A mid-summer night's dream.
- UVa:10057 A mid-summer night's dream
- HDU1247--Hat’s Words【STL--map】
- UVa1596 - Bug Hunt
- leetcode Divide Two Integers
- cookie、session、sessionid 与jsessionid
- 分书问题
- uva 10057 A mid-summer night’s dream(中位数)
- Android之fragment介绍及fragment详解
- com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxError Exception
- 解决android开发中eclipse不能自动提示
- 用jquery解析JSON数据的方法
- Unity技巧集合
- android:AndroidAnnotations上传文件,网络接口如此简洁
- “is not a core dump: File format not recognized”错误解决
- 周鸿祎谈:怎样才能成为一个优秀的产品经理?