POJ1166TheClock

The Clocks
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 15496 Accepted: 6286
Description

这里写图片描述

(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)
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

3 3 0
2 2 2
2 1 2
Sample Output

4 5 8 9
Source

IOI 1994

哎 感觉自己还是太菜了,最近做的几道枚举题都不是自己完全独立写出来的,路还很长,加油!

#include<iostream>
using namespace std;
int main()
{
    //枚举Move 
    int a[10],b[10],c[10];
    for(int i=1;i<=9;i++)
        cin>>a[i];
    for( b[1]=0;b[1]<4;b[1]++)
    for( b[2]=0;b[2]<4;b[2]++)
    for( b[3]=0;b[3]<4;b[3]++)
    for( b[4]=0;b[4]<4;b[4]++)
    for( b[5]=0;b[5]<4;b[5]++)
    for( b[6]=0;b[6]<4;b[6]++)
    for( b[7]=0;b[7]<4;b[7]++)
    for( b[8]=0;b[8]<4;b[8]++)
    for( b[9]=0;b[9]<4;b[9]++)
    {
        c[1]=(a[1]+b[1]+b[2]+b[4])%4;
        c[2]=(a[2]+b[1]+b[2]+b[3]+b[5])%4;
        c[3]=(a[3]+b[2]+b[3]+b[6])%4;
        c[4]=(a[4]+b[1]+b[4]+b[5]+b[7])%4;
        c[5]=(a[5]+b[1]+b[3]+b[5]+b[7]+b[9])%4;
        c[6]=(a[6]+b[3]+b[5]+b[6]+b[9])%4;
        c[7]=(a[7]+b[4]+b[7]+b[8])%4;
        c[8]=(a[8]+b[5]+b[7]+b[8]+b[9])%4;
        c[9]=(a[9]+b[6]+b[8]+b[9])%4;
        if(c[1]+c[2]+c[3]+c[4]+c[5]+c[6]+c[7]+c[8]+c[9]==0)
        {
            for(int i=1;i<=b[1];i++)    cout<<1<<" ";   
            for(int i=1;i<=b[2];i++)    cout<<2<<" ";   
            for(int i=1;i<=b[3];i++)    cout<<3<<" ";   
            for(int i=1;i<=b[4];i++)    cout<<4<<" ";   
            for(int i=1;i<=b[5];i++)    cout<<5<<" ";   
            for(int i=1;i<=b[6];i++)    cout<<6<<" ";   
            for(int i=1;i<=b[7];i++)    cout<<7<<" ";   
            for(int i=1;i<=b[8];i++)    cout<<8<<" ";   
            for(int i=1;i<=b[9];i++)    cout<<9<<" ";
            cout<<endl; 
        }
    }

     return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值