标签:href ted wro enc printf amp wrong class sequence
原文地址:https://www.cnblogs.com/Cloudcan/p/13326550.html
遵循两条原则:
1.某出栈元素之后出栈的各元素,若比其小(即在原队列中先进栈),必须为从大到小排序(即倒序);
2.最大的倒序数列,其元素数目不可以超过栈大小。例如5 6 4 3 7 2 1,最大倒序数列为5 4 3 2 1,若栈大小为4,则不可能存在该序列;
注:1.可以参考https://www.bilibili.com/video/BV125411W7Pa?from=search&seid=14950165865611086071;
1 int main(){ 2 int pop[1001]={0}; 3 int M,N,K,Y,count; 4 count=Y=M=N=K=0; 5 scanf("%d %d %d",&M,&N,&K); 6 for (int i = 0; i < K; ++i) { 7 for (int j = 0; j < N; ++j) { 8 scanf("%d",&pop[j+1]); 9 } 10 for (int k = N-2; k >0; --k) { 11 int p1; 12 p1=pop[k]; 13 for (int j = k+1; j < N+1; ++j) { 14 if(pop[j]<pop[k]){ 15 if(pop[j]<p1) { 16 p1 = pop[j]; 17 count++; 18 if(count>=M){ 19 Y=1; 20 goto wrong; 21 } 22 } 23 else{ 24 Y=1; 25 goto wrong; 26 } 27 } 28 } 29 count=0; 30 } 31 wrong: 32 Y?printf("NO\n"):printf("YES\n"); 33 Y=0; 34 count=0; 35 } 36 return 0; 37 }
02-线性结构4 Pop Sequence(PTA数据结构题)
标签:href ted wro enc printf amp wrong class sequence
原文地址:https://www.cnblogs.com/Cloudcan/p/13326550.html