CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » March 2010 Contest » Tri-Hexagonal Puzzle

Tri-Hexagonal Puzzle

Problem code: N4

  • All Submissions

All submissions for this problem are available.

Little Johnny wants to play with his friends today. But his babysitter won't let him go! After a lot of begging, the heartless nanny gives him her brand new electronic puzzle and says: "If you solve the puzzle then you are free to go". Not being aware of Little Johnny's IT skills, the nanny leaves the kid alone.

Rapidly, Little Johnny sends you an e-mail asking for your help.

The puzzle consists of three hexagons as shown in the figure. Each vertex is painted black or white. Some of them belong to just one hexagon and some of them belong to more than one. Exactly four of them are painted black, and the other nine are white. The goal is to make the shared vertexes black by means of allowed moves: rotating a hexagon 60 degrees clockwise or counter-clockwise.

Can you help Little Johnny?

Input

Input starts with an integer T, the number of puzzles to solve (1<=T<=100). T lines follow, each one having 13 binary digits, corresponding to the top-down, left to right labeling of the vertexes in the puzzle. A '0' means the i-th vertex is painted white, while a '1' means it is painted black.

Output

For each test case output M on a single line, the minimum number of moves required to solve the puzzle. Then print M lines, each one describing a move in the following manner: two space separated integers H and C, the rotated hexagon (upper left is 0, upper right is 1, lower one is 2) and the direction (0 for counter-clockwise, 1 for clockwise).

If there is more than one solution, any will suffice.

Example 1

TEST 1

Input:
1
0000000101011

Output:
3
2 0
2 0
1 1

Author: admin
Date Added: 5-02-2010
Time Limit: 1 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

can anyone please tell me

anurag_aggarwal @ 1 Mar 2010 04:09 PM
can anyone please tell me which vertex would be the first and which on would be the last

@Anurag The vertex labelling

Brian Drake @ 1 Mar 2010 05:23 PM

@Anurag The vertex labelling is "top-down, left to right". If you list the vertices in order, then all the vertices that are at the same height appear together. Vertices that are higher appear earlier. Among vertices at the same height, vertices that are more to the left appear earlier.

The figure, input and output given in the problem statement all refer to the same test case.

is it possibl that at some

akantev @ 2 Mar 2010 07:45 AM

is it possibl that at some intermediate stage, some of the points r overlapping so that < 4 pts r visibl?

Your question makes no sense.

triplem @ 2 Mar 2010 08:42 AM

Your question makes no sense. Read the problem statement again.

I havent been able to

akantev @ 2 Mar 2010 11:55 AM

I havent been able to understand the qn (apologies if this is very silly)...

suppose we take the case given in input

0000000101011

In the first step, suppose we perform the operation  1 0 i.e. rotate hex 1 counter clockwise. Then do we get 0000100101011? Or can we get both 0000100001011 and 0000100100011?

Thank you

@Vivek imagine the

shrikant169 @ 2 Mar 2010 12:19 PM

@Vivek

imagine the "tri-hexagon" as a framework of 13 cups. and there are 4 balls placed in these cups.

when a particular hexagon needs to be "rotated" then the balls on the perimeter of the hexagon are shifted.

hope this helps.

is the test i/o alrite?

devd @ 2 Mar 2010 09:42 PM

is the test i/o alrite?

Yes, the test I/O is alright.

admin @ 3 Mar 2010 03:34 PM

Yes, the test I/O is alright.

I think the input should

shreyash02 @ 3 Mar 2010 05:39 PM

I think the input should be 0000000101101.Does anyone else think so?

if moves should be minimum or

codegambler @ 3 Mar 2010 08:39 PM

if moves should be minimum or any number of moves?

@ shreyas - the input is

triplem @ 4 Mar 2010 02:52 AM

@ shreyas - the input is correct.

@ Pankaj - read the problem statement.

@shreyas, @Stephen If the

Brian Drake @ 4 Mar 2010 05:25 PM

@shreyas, @Stephen If the given labelling is “top-down, left to right”, then shreyas is using a labelling scheme that could be described as “left-right, top to bottom”. shreyas is looking at all the vertices in each column, then moving on to the next column; you should be looking at all the vertices in each row, then moving on to the next row.

What is memory usage limit??

piyushcsiitd @ 4 Mar 2010 09:53 PM

What is memory usage limit??

@piyush Like I said at

Brian Drake @ 5 Mar 2010 06:12 AM

@piyush Like I said at Traffic jam, “There is no fixed upper memory limit, but 64K is the lower limit for available memory.”

Little Johny may like to

devvrr @ 5 Mar 2010 03:00 PM

Little Johny may like to solve this himself

#venkat.....hehe

instance @ 5 Mar 2010 03:24 PM

#venkat.....hehe

can anybody explain the

dabbcomputers @ 6 Mar 2010 07:10 PM

can anybody explain the numbering of tst case with diagram ....

it is dificult to understand

dabbcomputers @ 6 Mar 2010 07:11 PM

it is dificult to understand because there are 15 vertex and 13 digit code..

1           2 3            4

abhayjit @ 7 Mar 2010 04:00 AM

1           2

3            4            5

6            7            8

9            10

11          12

13

@amritpal hope this helps

The formatting got

abhayjit @ 7 Mar 2010 04:03 AM
The formatting got  completely changed  in the previous post . 

         1                2
3               4                 5

6               7                 8
        9               10

        11              12
                13

Hi My code works perfectly on

Tyan Towers @ 8 Mar 2010 12:52 AM

Hi

My code works perfectly on my system, but here it is showing runtime error SIGSEV. What could be the reason? I used C++

i m new to coding can someone

rah.ag @ 10 Mar 2010 07:19 PM

i m new to coding can someone help me how to approach this problem!!

i hav understood the ques.

thanx

I need another test case that

dileep98490 @ 10 Mar 2010 08:46 PM

I need another test case that doesn't involve 3 black vertices on the same hexagon,just the input and the output is enough

It is your job to come up

triplem @ 11 Mar 2010 02:02 AM

It is your job to come up with your own test cases.

finally ... i was almost

f03nix @ 11 Mar 2010 05:29 AM

finally ... i was almost going to give up when i realized i was printing the result in wrong order :/

Check if my output format was

dileep98490 @ 11 Mar 2010 09:38 PM

Check if my output format was right for each test case

line-1:Number of rotations

next lines:single space seperated H and C in each line in order giving the corresponding rotation

my code is working fine with

w0rm @ 12 Mar 2010 11:11 AM

my code is working fine with some warnings in g++ 4.3 (fedora),but here its shows those warnings as error

any idea ?

You could try fixing them?

triplem @ 12 Mar 2010 11:16 AM

You could try fixing them?

What is the Judge computers

boxer @ 12 Mar 2010 03:15 PM

What is the Judge computers configuration?

I'm getting a TLE. On my comp, I can execute >100 test cases in under .5s.

#include<iostream> #inclu

murad007 @ 19 Mar 2010 06:47 PM
  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. using namespace std;
  5. #define MAXSTATES 70000
  6. #define N 15
  7. #define MAX_D 8
  8.  
  9. int state[N]={0},tmp;
  10.  
  11. int tmp_depth,cur_depth=0;
  12. int MAXDEPTH = MAX_D;
  13.  
  14. struct blk {
  15. int id;
  16. int clk_mov;
  17. }tmp_path[10],soln[10];
  18.  
  19. blk dp_sols[MAXSTATES];
  20.  
  21. void move_one_step(int mov_id,int clk_mov){
  22. if(clk_mov) {
  23. switch(mov_id) {
  24. case 0://rotate hexagon0
  25. tmp=state[1];
  26. state[1]=state[3];
  27. state[3]=state[6];
  28. state[6]=state[9];
  29. state[9]=state[7];
  30. state[7]=state[4];
  31. state[4]=tmp;
  32. break;
  33. case 1://rotate hexagon1
  34. tmp=state[2];
  35. state[2]=state[4];
  36. state[4]=state[7];
  37. state[7]=state[10];
  38. state[10]=state[8];
  39. state[8]=state[5];
  40. state[5]=tmp;
  41. break;
  42. case 2://rotate hexagon2
  43. tmp=state[7];
  44. state[7]=state[9];
  45. state[9]=state[11];
  46. state[11]=state[13];
  47. state[13]=state[12];
  48. state[12]=state[10];
  49. state[10]=tmp;
  50. }
  51. }
  52. else {
  53. switch(mov_id) {
  54. case 0://rotate hexagon0
  55. tmp=state[1];
  56. state[1]=state[4];
  57. state[4]=state[7];
  58. state[7]=state[9];
  59. state[9]=state[6];
  60. state[6]=state[3];
  61. state[3]=tmp;
  62. break;
  63. case 1://rotate hexagon1
  64. tmp=state[2];
  65. state[2]=state[5];
  66. state[5]=state[8];
  67. state[8]=state[10];
  68. state[10]=state[7];
  69. state[7]=state[4];
  70. state[4]=tmp;
  71. break;
  72. case 2://rotate hexagon2
  73. tmp=state[7];
  74. state[7]=state[10];
  75. state[10]=state[12];
  76. state[12]=state[13];
  77. state[13]=state[11];
  78. state[11]=state[9];
  79. state[9]=tmp;
  80. }
  81. }
  82. }
  83.  
  84. void com_back_one_step(int mov_id,int clk_mov){
  85. if(!clk_mov) {
  86. switch(mov_id) {
  87. case 0://rotate hexagon0
  88. tmp=state[1];
  89. state[1]=state[3];
  90. state[3]=state[6];
  91. state[6]=state[9];
  92. state[9]=state[7];
  93. state[7]=state[4];
  94. state[4]=tmp;
  95. break;
  96. case 1://rotate hexagon1
  97. tmp=state[2];
  98. state[2]=state[4];
  99. state[4]=state[7];
  100. state[7]=state[10];
  101. state[10]=state[8];
  102. state[8]=state[5];
  103. state[5]=tmp;
  104. break;
  105. case 2://rotate hexagon2
  106. tmp=state[7];
  107. state[7]=state[9];
  108. state[9]=state[11];
  109. state[11]=state[13];
  110. state[13]=state[12];
  111. state[12]=state[10];
  112. state[10]=tmp;
  113. }
  114. }
  115. else {
  116. switch(mov_id) {
  117. case 0://rotate hexagon0
  118. tmp=state[1];
  119. state[1]=state[4];
  120. state[4]=state[7];
  121. state[7]=state[9];
  122. state[9]=state[6];
  123. state[6]=state[3];
  124. state[3]=tmp;
  125. break;
  126. case 1://rotate hexagon1
  127. tmp=state[2];
  128. state[2]=state[5];
  129. state[5]=state[8];
  130. state[8]=state[10];
  131. state[10]=state[7];
  132. state[7]=state[4];
  133. state[4]=tmp;
  134. break;
  135. case 2://rotate hexagon2
  136. tmp=state[7];
  137. state[7]=state[10];
  138. state[10]=state[12];
  139. state[12]=state[13];
  140. state[13]=state[11];
  141. state[11]=state[9];
  142. state[9]=tmp;
  143. }
  144. }
  145. }
  146.  
  147. void bb() {
  148. int i , j , p , m;
  149.  
  150. if(cur_depth>=MAXDEPTH)
  151. return;
  152.  
  153. if ( state[4] && state[7] && state[9] && state[10]) {
  154.  
  155. MAXDEPTH=cur_depth;
  156. for(p=0;p<cur_depth;p++)
  157. {soln[p].id=tmp_path[p].id , soln[p].clk_mov=tmp_path[p].clk_mov;}
  158. for( m = 0 ; m < cur_depth ; m++ )
  159. cerr<<"("<<tmp_path[i].id<<" "<<tmp_path[i].clk_mov<<") ";cerr<<endl;
  160. tmp_depth=cur_depth;
  161. }
  162. for(i=0;i<3;i++) {
  163. for(j=0;j<2;j++) {
  164. move_one_step(i,j);
  165. tmp_path[cur_depth].id=i,tmp_path[cur_depth].clk_mov=j;
  166. cur_depth++;
  167. bb();
  168. com_back_one_step(i,j);
  169. cur_depth--;
  170. }
  171. }
  172. }
  173.  
  174.  
  175. int main()  {
  176.  
  177. int t;
  178. char inp[N];
  179.  
  180. scanf("%d",&t);
  181. while(t--) {
  182. cur_depth=0;
  183. MAXDEPTH=MAX_D;
  184. scanf("%s",inp);
  185. for(int i=0;i<13;i++)
  186. state[i+1]=inp[i]-'0';
  187.  
  188. /*for( i = 0 ; i < 13; i ++)
  189. cerr<<"state[i]="<<state[i];*/
  190. bb();
  191. //cerr<<"tmp_depth="<<tmp_depth<<endl;
  192. printf("%dn",tmp_depth);;
  193. for(int i=0;i<tmp_depth;i++) {
  194. printf("%d %dn",soln[i].id,soln[i].clk_mov);
  195. }
  196. //copy to dp_sols[]?
  197. }
  198. return 0;
  199. }

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com