Created
September 13, 2012 14:15
-
-
Save hyfrey/3714589 to your computer and use it in GitHub Desktop.
pat 1029
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cstdio> | |
| long int s1[1000010]; | |
| long int s2[1000010]; | |
| int main() | |
| { | |
| int M,N; | |
| scanf("%d", &M); | |
| for (int i = 0; i < M; i++) { | |
| scanf("%ld", &s1[i]); | |
| } | |
| scanf("%d", &N); | |
| for (int i = 0; i < N; i++) { | |
| scanf("%ld", &s2[i]); | |
| } | |
| int media_i = (M + N - 1) / 2; | |
| long int media = 0; | |
| int i,j; | |
| i = j = 0; | |
| while (i < M && j < N) { | |
| if (s1[i] == s2[j]) { | |
| media = s1[i]; | |
| i++; | |
| j++; | |
| if (i + j - 2 == media_i) { | |
| printf("%ld\n", media); | |
| return 0; | |
| } | |
| } else { | |
| if (s1[i] < s2[j]) { | |
| media = s1[i]; | |
| i++; | |
| } else if(s1[i] > s2[j]) { | |
| media = s2[j]; | |
| j++; | |
| } | |
| if (i + j - 1 == media_i) { | |
| printf("%ld\n", media); | |
| return 0; | |
| } | |
| } | |
| } | |
| if (j == N) { | |
| printf("%ld\n", s1[media_i - j]); | |
| return 0; | |
| } | |
| if (i == M) { | |
| printf("%ld\n", s2[media_i - i]); | |
| return 0; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment