1029. 这25%的中间值是多少呢?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1069个文字,预计阅读时间需要5分钟。
1029. 中位数(25%)时间限制:400ms 内存限制:65536kB 代码长度限制:16000B
题目:标准作答者:CHEN, Yue
给定一个递增序列S,包含N个整数,中位数是该序列中间位置的数。例如,对于序列[1, 3, 3, 6, 7, 8, 9],中位数是6。
1029. Median (25)
时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1={11, 12, 13, 14} is 12, and the median of S2={9, 10, 15, 16, 17} is 15. The median of two sequences is defined to be the median of the nondecreasing sequence which contains all the elements of both sequences. For example, the median of S1 and S2 is 13.
Given two increasing sequences of integers, you are asked to find their median.
Input
Each input file contains one test case. Each case occupies 2 lines, each gives the information of a sequence. For each sequence, the first positive integer N (<=1000000) is the size of that sequence. Then N integers follow, separated by a space. It is guaranteed that all the integers are in the range of long int.
Output
For each test case you should output the median of the two given sequences in a line.
Sample Input
4 11 12 13 14
5 9 10 15 16 17
Sample Output
13
K接着k个非降序的数
K2接着k2个非降序的数
求两队非降序在一起的中间数 如果k+k2为偶数,那么非降序的第(k+k2)/2;否则第(k+k2+1)/2个
评测结果
时间
结果
得分
题目
语言
用时(ms)
内存(kB)
用户
8月01日
17:15
答案正确
25
1029
C++ (g++ 4.7.2)
211
8184
datrilla
测试点
测试点
结果
用时(ms)
内存(kB)
得分/满分
0
答案正确
1
384
4/4
1
答案正确
1
384
2/2
10
答案正确
210
8032
3/3
11
答案正确
211
8184
1/1
12
答案正确
211
8024
3/3
13
答案正确
1
308
1/1
2
答案正确
1
244
4/4
3
答案正确
1
252
1/1
4
答案正确
1
384
1/1
5
答案正确
1
296
1/1
6
答案正确
102
4176
1/1
7
答案正确
103
4148
1/1
8
答案正确
102
4168
1/1
9
答案正确
103
4088
1/1
#include<iostream>
using namespace std;
int main()
{
int*s1, *s2;
int len1, len2, index1,index2, now, goal,goalindex;
scanf("%d", &len1);
s1 = (int*)malloc(sizeof(int)*len1);
for (index1 = 0; index1 < len1; index1++)
scanf("%d", &s1[index1]);
scanf("%d", &len2);
s2 = (int*)malloc(sizeof(int)*len2);
for (index2 = 0; index2 < len2; index2++)
scanf("%d", &s2[index2]);
goalindex = (len1 + len2+1) / 2;
index1 = 0;
index2 = 0;
now = 0;
while (index1 < len1&&index2 < len2&&now < goalindex)
{
goal = s1[index1] < s2[index2] ? s1[index1++] : s2[index2++];
now++;
}
if (now < goalindex&&index1 < len1)goal = s1[goalindex - now+index1-1];
else if (now < goalindex&&index2 < len2)goal = s2[goalindex - now + index2-1];
printf("%d\n",goal);
free(s2);
free(s1);
system("pause");
return 0;
}
本文共计1069个文字,预计阅读时间需要5分钟。
1029. 中位数(25%)时间限制:400ms 内存限制:65536kB 代码长度限制:16000B
题目:标准作答者:CHEN, Yue
给定一个递增序列S,包含N个整数,中位数是该序列中间位置的数。例如,对于序列[1, 3, 3, 6, 7, 8, 9],中位数是6。
1029. Median (25)
时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1={11, 12, 13, 14} is 12, and the median of S2={9, 10, 15, 16, 17} is 15. The median of two sequences is defined to be the median of the nondecreasing sequence which contains all the elements of both sequences. For example, the median of S1 and S2 is 13.
Given two increasing sequences of integers, you are asked to find their median.
Input
Each input file contains one test case. Each case occupies 2 lines, each gives the information of a sequence. For each sequence, the first positive integer N (<=1000000) is the size of that sequence. Then N integers follow, separated by a space. It is guaranteed that all the integers are in the range of long int.
Output
For each test case you should output the median of the two given sequences in a line.
Sample Input
4 11 12 13 14
5 9 10 15 16 17
Sample Output
13
K接着k个非降序的数
K2接着k2个非降序的数
求两队非降序在一起的中间数 如果k+k2为偶数,那么非降序的第(k+k2)/2;否则第(k+k2+1)/2个
评测结果
时间
结果
得分
题目
语言
用时(ms)
内存(kB)
用户
8月01日
17:15
答案正确
25
1029
C++ (g++ 4.7.2)
211
8184
datrilla
测试点
测试点
结果
用时(ms)
内存(kB)
得分/满分
0
答案正确
1
384
4/4
1
答案正确
1
384
2/2
10
答案正确
210
8032
3/3
11
答案正确
211
8184
1/1
12
答案正确
211
8024
3/3
13
答案正确
1
308
1/1
2
答案正确
1
244
4/4
3
答案正确
1
252
1/1
4
答案正确
1
384
1/1
5
答案正确
1
296
1/1
6
答案正确
102
4176
1/1
7
答案正确
103
4148
1/1
8
答案正确
102
4168
1/1
9
答案正确
103
4088
1/1
#include<iostream>
using namespace std;
int main()
{
int*s1, *s2;
int len1, len2, index1,index2, now, goal,goalindex;
scanf("%d", &len1);
s1 = (int*)malloc(sizeof(int)*len1);
for (index1 = 0; index1 < len1; index1++)
scanf("%d", &s1[index1]);
scanf("%d", &len2);
s2 = (int*)malloc(sizeof(int)*len2);
for (index2 = 0; index2 < len2; index2++)
scanf("%d", &s2[index2]);
goalindex = (len1 + len2+1) / 2;
index1 = 0;
index2 = 0;
now = 0;
while (index1 < len1&&index2 < len2&&now < goalindex)
{
goal = s1[index1] < s2[index2] ? s1[index1++] : s2[index2++];
now++;
}
if (now < goalindex&&index1 < len1)goal = s1[goalindex - now+index1-1];
else if (now < goalindex&&index2 < len2)goal = s2[goalindex - now + index2-1];
printf("%d\n",goal);
free(s2);
free(s1);
system("pause");
return 0;
}

