HDU 2918 Tobo or not Tobo

Source: Internet
Author: User

HDU 2918 Tobo or not Tobo

 

Tobo or not ToboTime Limit: 2000/1000 ms (Java/Other) Memory Limit: 32768/32768 K (Java/Other) Total Submission (s): 2 Accepted Submission (s ): 1 Problem Description The game of Tobo is played on a plastic board designed into a 3 × 3 grid with cells numbered from 1 to 9 as shown in figure (). the grid has four dials (labeled ''a to ''d in the figure .) each dial can be rotated in 90 degrees increment in either direction. rotating a dial causes the four cells currently adjacent to it to rotate along. for example, figure (B) shows the Tobo after rotating dial' A once in a clockwise ction. figure (c) shows the Tobo in figure (B) after rotating dial' D once in a counterclockwise ction.




Kids love to challenge each other playing the Tobo. starting with the arrangement shown in figure (a), (which we'll call the standard arrangement,) one kid wowould randomly rotate the dials, X number of times, in order to ''shuffle the board. another kid then tries to bring the board back to its standard arrangement, taking no more than X rotations to do so. the less rotations are needed to restore it, the better. this is where you see a business opportunity. you woshould like to define these kids a program to advise them on the minimum number of steps needed to bring a Tobo back to its standard arrangement.
Input Your program will be tested on one or more test cases. each test case is specified on a line by itself. each line is made of 10 decimal digits. let's call the first digit Y. the remaining 9 digits are non-zeros and describe the current arrangement of the Tobo in a row-major top-down, left-to-right ordering. the first sample case corresponds to figure (c ). the last line of the input file is a sequence of 10 zeros.
Output For each test case, print the result using the following format: k. R where k is the test case number (starting at 1,) is a single space, and R is the minimum number of rotations needed to bring the Tobo back to its standard arrangement. if this can't be done in Y dials or less, then R =-1.
Sample Input
341356972811654327890000000000

Sample Output
1. 22. -1

 

IDA *

 

Estimated distance from Manhattan

Pruning the previous layer. If point A turns clockwise to the next layer, point A turns counter-clockwise.

 

 

#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include 
     
      using namespace std;int dir[4][4]= {{3,0,4,1},{4,1,5,2},{6,3,7,4},{7,4,8,5}};int ddir[4][4]= {0,1,3,4,1,2,4,5,3,4,6,7,4,5,7,8};char str[20];int abs(int n){    if(n<0) return 0-n;    return n;}int get_h(int a[3][3]){    int ans=0;    for(int i=0; i<3; i++)    {        for(int j=0; j<3; j++)        {            ans+=abs(i-(a[i][j]-1)/3)+abs(j-(a[i][j]-1)%3);        }    }    return (ans+3)/4;}bool dfs(int len,int a[3][3],int kind,int kind2){    if(len
      
       length) printf(-1); } return 0;}
      
     
    
   
  
 


 

 

 

 

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.