[SCU 4497] Goozy game time (based on search time pruning)

Source: Internet
Author: User

SCU-4497

Given a n*n puzzle, ask to rearrange
Makes a block that is adjacent to each other on the same number of squares connected

It's rather disgusting.
I've just begun to move in the set by saving each line of work, and the result is a mle.

Later, a different idea, snake to find a block to connect
And then tried a few pruning, the effect is not ideal

Generate several sets of random data yourself
found that when the numbers are 0~3, compared to the concentration, run huge slow
It would have been 0~3 this repeatable probability was larger.
It is also possible to search the solution accordingly.
But without a solution, he would repeat the search, a waste of time.

Based on the above facts, I used a metaphysical pruning
I set a number of searches, and when the number of Dfs calls is too large, return as no solution
Probably WA three or four hair appearance, tried out the better parameters, 72ms ran over

Later I looked for the ZW chicory to ask the standard course, found that the calibration process is based on the above conditions for special pruning
But his pruning is more than my science.

#pragma COMMENT (linker, "/stack:102400000,102400000")#include <cstdio>#include <iostream>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include <map>#include <set>#include <queue>using namespace STD;typedefpair<int,int> Pii;typedef Long LongLL;typedef unsigned Long LongULL;typedef DoubleDBL;typedef Long DoubleLdbl;#define MST (A, B) memset (A,b,sizeof (a) )#define CLR (a) MST (a,0)#define SQR (a) (a*a)Const intup=0, right=1, down=2, left=3;Const intTime=1e5;structnode{intn[4];};intN;node inpt[ -];intcnt[ -][ -];intmap[ -][ -];BOOLvis[ -];intNtime=0;intDfsint);voidGetcor (int,int&,int&);voidChangeint,int);BOOLCheckint);intMain () {#ifdef LOCALFreopen ("In.txt","R", stdin);//Freopen ("OUT.txt", "w", stdout);    #endif    intTscanf("%d", &t); for(intck=1; ck<=t; ck++) {ntime=0; CLR (VIS); CLR (CNT); CLR (MAP);scanf("%d", &n); for(intI=0; i<n*n; i++) for(intj=0; j<4; J + +) {scanf("%d", &inpt[i].n[j]);        cnt[j][inpt[i].n[j]]++; }if(Dfs (0) &&ntime<=time)puts("Possible");Else{puts("Impossible"); }//printf ("%lld\n", ntime);}return 0;}intDfsintStep) {if(++ntime>time)return 1;if(step==n*n)return 1; for(intI=0; i<n*n; i++) {if(Vis[i])Continue;intx, y; Getcor (Step,x,y);if(x && inpt[i].n[up]! = inpt[map[x-1][y]].n[down])Continue;if(x&1)        {if(y+1<n && inpt[i].n[right]! = inpt[map[x][y+1]].n[left])Continue; vis[i]=1; Map[x][y]=i;if(Dfs (step+1))return 1; map[x][y]=0; vis[i]=0; }Else{if(y && inpt[i].n[left]! = inpt[map[x][y-1]].n[right])Continue; vis[i]=1; Map[x][y]=i;if(Dfs (step+1))return 1; map[x][y]=0; vis[i]=0; }    }return 0;}voidGetcor (intStepint&x,int&y) {x=step/n;if(x&1) y=n-1-step%n;Elsey=step%n;}

[SCU 4497] Goozy game time (based on search time pruning)

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.