0 of 1 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 1 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
(两元序列)试求一个整数序列中,最长的仅包含两个不同整数的连续子序列。如有多 个子序列并列最长,输出任意一个即可。例如,序列 1 1 2 3 2 3 2 3 3 1 1 1 3 1中, 有两段满足条件的最长子序列,长度均为 7,分别用下划线和上划线标出。 (2013年提高组)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
#include <stdio.h> #include <string.h> #define SIZE 100 int n, m, p, count; int a[SIZE][SIZE]; void colour(int x, int y) { count++; a[x][y] = 1; if ((x > 1) && (a[x - 1][y] == 0)) colour(x - 1, y); if ((y > 1) && (a[x][y - 1] == 0)) colour(x, y - 1); if ((x < n) && (a[x + 1][y] == 0)) colour(x + 1, y); if ((y < m) && (a[x][y + 1] == 0)) colour(x, y + 1); } int main() { int i, j, x, y, ans; memset(a, 0, sizeof(a)); scanf("%d%d%d", &n, &m, &p); for (i = 1; i <= p; i++) { scanf("%d%d", &x, &y); a[x][y] = 1; } ans = 0; for (i = 1; i <= n; i++) for (j = 1; j <= m; j++) if (a[i][j] == 0) { count = 0; colour(i, j); if (ans < count) ans = count; } printf("%d\n", ans); return 0; } |
填空一: 填空二: 填空三:
填空四: 填空五: