Link: http://pat.zju.edu.cn/contests/ds/2-13
It is known that there are two unequal non-descending sequence S1 and S2. The design function calculates the median of the union of S1 and S2. Sequential sequence A0, A1... The median of An-1 refers to the value of a (N-1)/2, that is, the number of [(n + 1)/2] (A0 is 1st ).
Input format description:
The input is divided into three rows. The first row shows the common length of the sequence N (0 <n <= 1st). Then, each row enters the information of a sequence, that is, N non-descending integers. Numbers are separated by spaces.
Output format description:
Output the median of the Union sequence of two input sequences in one row.
Sample input and output:
Serial number |
Input |
Output |
1 |
51 3 5 7 92 3 4 5 6 |
4 |
2 |
6-100 -10 1 1 1 1-50 0 2 3 4 5 |
1 |
3 |
31 2 34 5 6 |
3 |
4 |
34 5 61 2 3 |
3 |
5 |
121 |
1 |
PS:
This question is full of tears. I blame myself for my own IQ. When I saw the Union in the question, I took a great deal and then ...... In the last case, WA won't be able to pass the discussion! I used various methods ............
The Code is as follows:
# Include <cstdio> # include <cstring> const int maxn = 100017; int A [maxn], B [maxn], C [maxn]; int main () {int N; while (~ Scanf ("% d", & N) {for (INT I = 0; I <n; I ++) {scanf ("% d ", & A [I]) ;}for (INT I = 0; I <n; I ++) {scanf ("% d", & B [I]);} int L = 0; int I = 0, j = 0; while (I <n & J <n) {if (a [I] = B [J]) {c [L ++] = A [I]; C [L ++] = B [J]; // This line does not start with wa to vomit I ++, j ++;} if (a [I] <B [J]) {C [L ++] = A [I]; I ++ ;} else {C [L ++] = B [J]; j ++ ;}} while (I <n) {C [L ++] = A [I]; I ++;} while (j <n) {C [L ++] = B [J]; j ++;} printf ("% d \ n ", c [L-1)/2]);} return 0 ;}
2-13. Median of two ordered sequences (25) (zjupat)