AOJ 0033 Ball

Source: Internet
Author: User

Test Instructions

The topic I came down, I roughly explained. There are numbered 1 to 10 a total of 10 balls, from the top throw down, the entrance can choose to go to the left or right, the last 10 balls all fall down if both sides are small to large order, then output yes;

Code

At first I tested my understanding of the test instructions is not right:

#include <iostream>#include <vector>using namespace STD;intMain () { vector<int>Left vector<int>Right vector<int>AllBOOLFlag =true;intNCin>> N;if(n = =0)return-1; for(inti =0; I < n; i++) { for(intj =0; J <Ten; J + +) {intTempCin>> temp;        All.push_back (temp); }    } for(inti =0; I < n; i++) { for(intj =0; J <Ten; J + +) {if(Left.size () >0) {if(all[Ten* i + j] > Left[left.size ()-1]) {Left.push_back (all[Ten* i + j]); }Else{if(Right.size () >0) {if(all[Ten* i + j] > Right[right.size ()-1]) Right.push_back (all[Ten* i + j]);ElseFlag =false; }Else{Right.push_back (all[Ten* i + j]); }                }            }Else{Left.push_back (all[Ten* i + j]); }        }if(flag)cout<<"YES"<< Endl;Else            cout<<"NO"<< Endl; Flag =true; }return 0;}

Later submitted code incredibly wrong, what the devil!! I use the use case test in the topic is right, still did not find out why ...

Because know test instructions is required to use DFS, so change the code, the same idea, try again:

#include <stdio.h>#include <queue>using namespace STD;BOOLFlag =true;voidSolve Queue<int>Left Queue<int>Right Queue<int>All) {if(All.size () >0) {if(Left.size () >0) {if(All.front () > Left.back ())                {Left.push (All.front ());                All.pop ();            Solve (left, right, all); }Else{if(Right.size () >0) {if(All.front () > Right.back ())                        {Right.push (All.front ());                        All.pop ();                    Solve (left, right, all); }Else if(all.size () = =0){                    }Else{flag =false; }                }Else{Right.push (All.front ());                    All.pop ();                Solve (left, right, all); }            }        }Else{Left.push (All.front ());            All.pop ();        Solve (left, right, all); }    }}intMain () {intNscanf("%d", &n); for(; n >0; n--) { Queue<int>All Queue<int>Left Queue<int>Right for(inti =0; I <Ten; i++) {intTempscanf("%d", &temp);        All.push (temp); } solve (left, right, all);if(flag)printf("yes\n");Else            printf("no\n"); }return 0;}

This time finally can, prove my train of thought no problem!

Get a copy of the code here, the variables are quite many:

#include <iostream>#include <stack>#include <queue>using namespace STD;intMain () { Stack<int>b, C;inta[Ten];BOOLwhich[ One];intdata[ One];intIndexintN, M, A;intI, J;Cin>> N; for(i =0; i<n; i++) {index =0; for(j =0; j<Ten; J + +) {Cin>> m;            A[j] = m; Data[j +1] =0; } B.push (0); C.push (0); while(Index >=0) {A = A[index];if(B.top () < A && (Data[a]! =1&& Data[a]! =3) {B.push (A); Data[a] + =1; Which[a] =true; }Else if(C.top () < A && (Data[a]! =2&& Data[a]! =3) {C.push (A); Data[a] + =2; Which[a] =false; }Else{index--;if(Index <0) { Break; }Else if(Which[a[index]])                {B.pop (); }Else{C.pop (); }Continue; } index++;if(Index >9) {cout<<"YES"<< Endl; Break; }        }if(Index <0) {cout<<"NO"<< Endl; }    }}
Extras

Ask for votes or forward support ... I hope I don't die too badly ...

Please click here: Vote

Voting starts from number 10th and continues to number 20th, please!


—————— Of course you can also click on the image directly

AOJ 0033 Ball

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.