1166 The Clocks

 
The Clocks
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 3980 Accepted: 1434

Description

 

Input
Your program is to read from standard input. Nine numbers give the start positions of the dials. 0=12 o'clock, 1=3 o'clock, 2=6 o'clock, 3=9 o'clock.

Output
Your program is to write to standard output. Output a shortest sorted sequence of moves (numbers), which returns all the dials to 12 o'clock. You are convinced that the answer is unique.

Sample Input

 

Sample Output

 

Source
IOI 1994

 *********************************************************************************

**************************************************************************************

  • Source Code
    # include <iostream.h>
    
    int move[9][9]={
       //A,B,C,D,E,F,G,H,I
    	{1,1,0,1,1,0,0,0,0},//move1
    	{1,1,1,0,0,0,0,0,0},//move2
    	{0,1,1,0,1,1,0,0,0},//move3
    	{1,0,0,1,0,0,1,0,0},//move4
    	{0,1,0,1,1,1,0,1,0},//move5
    	{0,0,1,0,0,1,0,0,1},//move6
    	{0,0,0,1,1,0,1,1,0},//move7
    	{0,0,0,0,0,0,1,1,1},//move8
    	{0,0,0,0,1,1,0,1,1} //move9
    };
    int clock[9];//original
    int temp[9];//for try
    int m[9];//record the times of each move
    
    void LoadClock();
    void Move();
    bool Check();
    void Output();
    
    void main(){
    	
    	LoadClock();
    
    	for (m[0]=0;m[0]<=3;m[0]++)
    	for (m[1]=0;m[1]<=3;m[1]++)
    	for (m[2]=0;m[2]<=3;m[2]++)
    	for (m[3]=0;m[3]<=3;m[3]++)
    	for (m[4]=0;m[4]<=3;m[4]++)
    	for (m[5]=0;m[5]<=3;m[5]++)
    	for (m[6]=0;m[6]<=3;m[6]++)
    	for (m[7]=0;m[7]<=3;m[7]++)
    	for (m[8]=0;m[8]<=3;m[8]++)
    	{
    		
    		Move();
    		if (Check()==true){
    			Output();
    			break;
    		}		
    	}
    }
    
    void LoadClock(){
    	int i;
    	for (i=0;i<9;i++)
    		cin>>clock[i];
    }
    
    void Move(){
    	int i,j;
    	for (i=0;i<9;i++){
    		temp[i]=clock[i];
    		for (j=0;j<9;j++) if(move[j][i])
    			temp[i] += m[j];
    		temp[i] %= 4;
    	}
    }
    
    bool Check(){
    	int i;
    	for (i=0;i<9;i++)	if (temp[i]!=0)	return false;
    	return true;
    }
    
    void Output(){
    	int i,j;
    	for (i=0;i<9;i++){
    		if (m[i]>0)
    			for (j=0;j<m[i];j++)
    				cout<<i+1<<' ';
    	}
    	cout<<endl;
    }
    
    
    
    
  • 4 5 8 9

    3 3 0
    2 2 2
    2 1 2

    |-------|    |-------|    |-------|
    
    | | | | | | |
    |---O | |---O | | O |
    | | | | | |
    |-------| |-------| |-------|
    A B C

    |-------| |-------| |-------|
    | | | | | |
    | O | | O | | O |
    | | | | | | | | |
    |-------| |-------| |-------|
    D E F

    |-------| |-------| |-------|
    | | | | | |
    | O | | O---| | O |
    | | | | | | | |
    |-------| |-------| |-------|
    G H I
    (Figure 1)

    There are nine clocks in a 3*3 array (figure 1). The goal is to return all the dials to 12 o'clock with as few moves as possible. There are nine different allowed ways to turn the dials on the clocks. Each such way is called a move. Select for each move a number 1 to 9. That number will turn the dials 90' (degrees) clockwise on those clocks which are affected according to figure 2 below.
    Move   Affected clocks
    

    1 ABDE
    2 ABC
    3 BCEF
    4 ADG
    5 BDEFH
    6 CFI
    7 DEGH
    8 GHI
    9 EFHI
    (Figure 2)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xcl119xxcl

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值