解题代码
#include<stdio.h>
#include<stdlib.h>
int main()
{
int M, N, num, i, j, l, k, isFirst = 1, *pstack, last;
scanf("%d %d %d", &M, &N, &num);
int *stack = (int*)malloc((M + 1) * sizeof(int));
int *flag = (int*)malloc(num * sizeof(int));
stack[0] = 0;
for (i = 0; i < num; i++) {
//printf("case%d:\n", i+1);
flag[i] = 1;
last = 0;
pstack = stack;
for (j = 0; j < N; j++) {
scanf("%d", &k);
//printf("\t第%d个数:\n", j + 1);
//printf("\t\tk=%d,*pstack=%d\n", k, *pstack);
if (k <= *pstack) {
if (!flag[i]) continue;
if (k == *pstack) {
//printf("\t\t--pstack\n");
--pstack;
}
else {
//printf("\t\t\tflag[%d]=0\n", i);
flag[i] = 0;
}
}
else {
if (!flag[i]) continue;
else {
if (k > M + j) {
flag[i] = 0;
//printf("\t\t\tflag[%d]=0\n", i);
continue;
}
for (l = last + 1; l < k; l++) {
//printf("\t\t\tl=%d\n", l);
*++pstack = l;
last = l + 1;
}
}
}
if (k > last) {
last = k;
}
}
}
for (i = 0; i < num; i++) {
if (isFirst) {
isFirst = 0;
}
else {
printf("\n");
}
if (flag[i]) {
printf("YES");
}
else {
printf("NO");
}
}
return 0;
}
测试结果
问题整理
1.利用printf调试,利用得当会顺利debug。
2.
3.