现在的位置: 首页 > 综合 > 正文

poj The Clocks 1166

2015年02月08日 ⁄ 综合 ⁄ 共 1036字 ⁄ 字号 评论关闭

/*
题意:给一个3*3的图,每个数字都在0-3的范围内,0代表钟表12点,1代表3点,2,3,分别代表6点和9点有九种方式
移动,每种移动特定的几个,每次移动都顺势针移动90度
*/
#include<stdio.h>
int main()
{
    int a[15],b[15],c[15],i;
    for(i=1; i<=9; i++)
        scanf("%d",&a[i]);
    //枚举每种移动多少次
    for(b[1]=0; b[1]<=3; b[1]++)
    for(b[2]=0; b[2]<=3; b[2]++)
    for(b[3]=0; b[3]<=3; b[3]++)
    for(b[4]=0; b[4]<=3; b[4]++)
    for(b[5]=0; b[5]<=3; b[5]++)
    for(b[6]=0; b[6]<=3; b[6]++)
    for(b[7]=0; b[7]<=3; b[7]++)
    for(b[8]=0; b[8]<=3; b[8]++)
    for(b[9]=0; b[9]<=3; b[9]++)
    {
         c[1]=(a[1]+b[1]+b[2]+b[4])%4;//钟表1的最后时间为原始时间a[1],加上第一种移动的次数,第二种移动的次数加上第四种移动的次数后对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;
         int sum=-1;
         for(int i=1; i<=9; i++)
            sum+=c[i];
        if(sum+1==0)
        {
            for(int i=1;i<=9;i++)
            {
                for(int j=1;j<=b[i];j++)
                    printf("%d ",i);
            }
            return 0;
        }
    }
}

【上篇】
【下篇】

抱歉!评论已关闭.