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; }
uva 10057 A mid-summer night’s dream(中位数)
原文地址:http://blog.csdn.net/llx523113241/article/details/43741627