uva 10057 A mid-summer night's dream.(检索)
来源:互联网 发布:网络教育春季报名 编辑:程序博客网 时间:2024/05/04 11:21
题目连接:10057 A mid-summer night's dream.
题目大意:找到使得给出算式最小的值,如果有多个,输出最小的,然后在输出所给的数组A中有多少个数值可以满足算式最小(相等的要分开计算),随后输出有多少个整数满足算式值虽小(没有在数组A中出现也要计算)。
解题思路:本体主要题目转换后就是找数组A的中位数,如果给出的n为奇数, 所要找的就是中间的那个值,然后遍历A统计相等的个数就可以了, ans就是1.
如果n为偶数,所要找的就是中间两个,而且由A[a] 到A[b]之间所有整数都满足。
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;const int N = 1000005;int n, num[N];int count(int cur) { int cnt = 0; for (int i = 0; i < n; i++) {if (num[i] == num[cur]) cnt++;else if (num[i] > num[cur]) break; } return cnt;}int main() { int cur, cnt, sum; while (scanf("%d", &n) == 1) {cur = n / 2;for (int i = 0; i < n; i++) scanf("%d", &num[i]);sort(num, num + n);if (n % 2) { sum = count(cur); cnt = 1;}else { sum = count(--cur); if (num[cur] == num[cur + 1])cnt = 1; else {cnt = num[cur + 1] - num[cur] + 1;sum += count(cur + 1); }}printf("%d %d %d\n", num[cur], sum, cnt); } return 0;}
- 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.
- 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 10057A 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.
- struts2 Error filterStart问题
- nfs启动出现网络断开Try to bring eth0 interface up....../etc/init.d/ifconfig-eth0: line 6: grep: not found
- iframe 跟ie,firefox,chrome 的爱恨情仇
- 程序员最重要的技能
- [leetcode] Palindrome Partitioning II
- uva 10057 A mid-summer night's dream.(检索)
- 几种开放源码的TCPIP协议栈概述--LwIP,uIP,TinyTcp和uC/IP
- POJ 2063 Investment 完全背包
- WIN7自带的虚拟键盘
- Java程序栈信息文件中的秘密(五)
- x86架构下函数堆栈恢复方法
- spring注入方式之AutoWired注入
- 再学习sqlhelper
- struts1源码解析_struts加载struts-config.xml