# 2016 Blue Bridge Cup c++a group seventh cut stamps

Source: Internet
Author: User

Choose 5 (DFS) from small to large from 1-12

BFS to determine whether the 5 number is connected: to any one (my program gets the smallest) as the starting point, BFS Search can be found to 5 if it can be explained that is connected

`#include <iostream>#include<stdio.h>#include<cmath>#include<queue>using namespacestd;inta[ -] = {0};//DFSintl;//Store 5 numbers that have been foundintsum =0; typedefstructnode{intx, y; structnode () {x= -1; Y= -1; }    structNodeintXxintyy) {x=xx; Y=yy; }}node;BOOLOk () {//BFS Determines if the 5 numbers found are connected    intarr;//storing shear matrices    intflag;  for(inti =0; i<3; i++){         for(intj =0; j<4; J + +) {Arr[i][j]=0;//whether the mark is accessible during the BFS processFLAG[I][J] =0;//whether the mark has been accessed during the BFS process        }    }     for(inti =0; i<5; i++) {arr[(L[i]-1)/4[(l[i]-1)%4]=1; }    /*cout << "arr:" << Endl;            for (int i = 0, i<3; i++) {for (int j = 0; j<4; j + +) {cout << arr[i][j];        cout << "";    } cout << Endl; }*/    intdir{//Upper and lower left direction control{ -1,0},        { 1,0 },        { 0, -1 },        { 0,1 }    }; Queue<Node>Q; Node vs ((l -1) /4, (l -1) %4); FLAG[VS.X][VS.Y]=1;    Q.push (VS); intSsum =1;    Node vn, VW;  while(Q.empty () = =false) {vn=Q.front ();        Q.pop ();  for(inti =0; i<4; i++) {vw.x= vn.x + dir[i]; Vw.y= VN.Y + dir[i]; //cout << vw.x << vw.y << Endl;            /*cout << "flag:" << Endl;                    for (int i = 0, i<3; i++) {for (int j = 0; j<4; j + +) {cout << flag[i][j];                cout << "";            } cout << Endl; }*/            //GetChar ();            if(Vw.x >=0&& vw.x <=2&& vw.y >=0&& vw.y <=3){                if(Flag[vw.x][vw.y] = =0&& Arr[vw.x][vw.y] = =1){//If the pity Dorado has not been accessed and the point is accessibleFLAG[VW.X][VW.Y] =1;//flag that the node has visitedQ.push (VW); Ssum++; }            }        }    }    //cout << ssum << Endl;    if(Ssum = =5)return true; return false;}voidDfsintx) {    if(x>1&& (L[x-1]<l[x-2]))return;//decline, don't .    if(x = =5&&OK ()) {        /*for (int i = 0; i<5; i++) {printf ("%d", l[i]); } printf ("\ n");*/sum= Sum +1; //printf ("Print%d\n", sum);        return; }    if(x = =5)return;  for(inti =1; i< -; i++){        if(A[i] = =0) {L[x]=i; A[i]=1; DFS (x+1); A[i]=0; }    }}intMain () {DFS (0); cout<< sum <<Endl;}`

2016 Blue Bridge Cup c++a group seventh cut stamps

Related Keywords:
Related Article

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.