02-Linear Structure 4 Pop Sequence (25 min)
Given a stack which can keepM numbers at the most. Pushn numbers in the order of 1, 2, 3, ..., < Span class= "Katex" >n and pop randomly. You were supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For example, If m is 5 and n is 7, we can obtain 1, 2, 3, 4, 5, 6, 7 from the stack, and not 3, 2, 1, 7, 5, 6, 4.
Input Specification:
Each input file contains the one test case. For each case, the first line contains 3 numbers (all no more than 1000):M (the maximum capacity of the stack),< Span class= "Mord mathit" >n (the length of push sequence), And k (the number of pop sequences to be checked). Then k lines follow, each contains a pop sequence of < Span class= "Katex" >n numbers. All the numbers in a line is separated by a space.
Output Specification:
For each pop sequence, print on one line "YES" if it is indeed a possible pops sequence of the stack, or "NO" if not.
Sample Input:
5 7 51 2 3 4 5 6 73 2 1 7 5 6 47 6 5 4 3 2 15 6 4 3 7 2 11 7 6 5 4 3 2
Sample Output:
YESNONOYESNO
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;classt{Static voidMain (string[] args) { varline = Console.ReadLine (). Split (New[] {" "}, Stringsplitoptions.removeemptyentries); varMaxnum =int. Parse (line[0]); varLineNum =int. Parse (line[1]); varLineCount =int. Parse (line[2]); List<string> list =Newlist<string>(); for(inti =0; i < LineCount; i++) {list. ADD (Console.ReadLine ()); } foreach(varIteminchlist) { stringY ="YES"; varNUMSS = Item. Split (New[] {" "}, Stringsplitoptions.removeemptyentries); List<int> nums =Newlist<int>(); foreach(varItem2inchNUMSS) {nums. ADD (int. Parse (ITEM2)); } for(inti =0; I < Nums. Count; i++) { if(I >0) { if(Nums[i-1]-Nums[i] >1) {Y="NO"; Break; } } if(Nums[i] >maxnum) {Y="NO"; Break; } Else { for(intj = i +1; J < Nums. Count; J + +) { if(Nums[i] <Nums[j]) {Nums[j]--; }}}} Console.WriteLine (Y); } }}
02-Linear Structure 4 Pop Sequence (25 min)