操作间没有次序关系,同一个操作最多重复3次。。。

可以直接暴力。。。

The Clocks
IOI'94 - Day 2

Consider nine clocks arranged in a 3x3 array thusly:

|-------|    |-------|    |-------|
| | | | | | |
|---O | |---O | | O |
| | | | | |
|-------| |-------| |-------|
A B C |-------| |-------| |-------|
| | | | | |
| O | | O | | O |
| | | | | | | | |
|-------| |-------| |-------|
D E F |-------| |-------| |-------|
| | | | | |
| O | | O---| | O |
| | | | | | | |
|-------| |-------| |-------|
G H I

The goal is to find a minimal sequence of moves to return all the dials to 12 o'clock. Nine different ways to turn the dials on the clocks are supplied via a table below; each way is called a move. Select for each move a number 1 through 9 which will cause the dials of the affected clocks (see next table) to be turned 90 degrees clockwise.

Move Affected clocks
1 ABDE
2 ABC
3 BCEF
4 ADG
5 BDEFH
6 CFI
7 DEGH
8 GHI
9 EFHI

Example

Each number represents a time according to following table:

9 9 12       9 12 12       9 12 12        12 12 12      12 12 12
6 6 6 5 -> 9 9 9 8-> 9 9 9 4 -> 12 9 9 9-> 12 12 12
6 3 6 6 6 6 9 9 9 12 9 9 12 12 12

[But this might or might not be the `correct' answer; see below.]

PROGRAM NAME: clocks

INPUT FORMAT

Lines 1-3: Three lines of three space-separated numbers; each number represents the start time of one clock, 3, 6, 9, or 12. The ordering of the numbers corresponds to the first example above.

SAMPLE INPUT (file clocks.in)

9 9 12
6 6 6
6 3 6

OUTPUT FORMAT

A single line that contains a space separated list of the shortest sequence of moves (designated by numbers) which returns all the clocks to 12:00. If there is more than one solution, print the one which gives the lowest number when the moves are concatenated (e.g., 5 2 4 6 < 9 3 1 1).

SAMPLE OUTPUT (file clocks.out)

4 5 8 9

Submission file Name:

USACO Gateway |   
Comment or Question

/*
ID:qhn9992
PROG:clocks
LANG:C++11
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; int a[10],c[10];
int b[10][10]
={ 0,0,0,0,0,0,0,0,0,0,
1,1,0,1,1,0,0,0,0,0,
1,1,1,0,0,0,0,0,0,0,
0,1,1,0,1,1,0,0,0,0,
1,0,0,1,0,0,1,0,0,0,
0,1,0,1,1,1,0,1,0,0,
0,0,1,0,0,1,0,0,1,0,
0,0,0,1,1,0,1,1,0,0,
0,0,0,0,0,0,1,1,1,0,
0,0,0,0,1,1,0,1,1,0
}; int main()
{
freopen("clocks.in","r",stdin);
freopen("clocks.out","w",stdout);
int cnt=0; for(int i=1;i<=9;i++)
{
scanf("%d",a+i);
a[i]=(a[i]/3)%4;
}
for(c[1]=0;c[1]<4;c[1]++)
{
for(c[2]=0;c[2]<4;c[2]++)
{
for(c[3]=0;c[3]<4;c[3]++)
{
for(c[4]=0;c[4]<4;c[4]++)
{
for(c[5]=0;c[5]<4;c[5]++)
{
for(c[6]=0;c[6]<4;c[6]++)
{
for(c[7]=0;c[7]<4;c[7]++)
{
for(c[8]=0;c[8]<4;c[8]++)
{
for(c[9]=0;c[9]<4;c[9]++)
{
///check....
bool flag=true;
for(int i=1;i<=9;i++)
{
int t=a[i];
for(int j=1;j<=9;j++)
{
t+=b[j][i-1]*c[j];
}
t=t%4;
if(t)
{
flag=false;
break;
}
}
if(flag)
{
for(int i=1;i<=9;i++)
{
while(c[i]--)
{
if(flag)
{
flag=false;
}
else putchar(32);
printf("%d",i);
}
}
putchar(10);
return 0;
}
else continue;
}
}
}
}
}
}
}
}
}
return 0;
}

USACO The Clocks的更多相关文章

  1. 【USACO】clocks 遇到各种问题 最后还是参考别人的思路

    //放在USACO上一直通不过 不知道哪里出了问题 输出的n总是等于1 但是BFS递归的次数是对的 <----这个问题解决了 局部变量压入queue中返回就是对的了 #include<io ...

  2. USACO 6.5 The Clocks

    The ClocksIOI'94 - Day 2 Consider nine clocks arranged in a 3x3 array thusly: |-------| |-------| |- ...

  3. USACO chapter1

    几天时间就把USACO chapter1重新做了一遍,发现了自己以前许多的不足.蒽,现在的程序明显比以前干净很多,而且效率也提高了许多.继续努力吧,好好的提高自己.这一章主要还是基本功的训练,没多少的 ...

  4. USACO 完结的一些感想

    其实日期没有那么近啦……只是我偶尔还点进去造成的,导致我没有每一章刷完的纪念日了 但是全刷完是今天啦 讲真,题很锻炼思维能力,USACO保持着一贯猎奇的题目描述,以及尽量不用高级算法就完成的题解……例 ...

  5. USACO . Your Ride Is Here

    Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often co ...

  6. 【USACO 3.1】Stamps (完全背包)

    题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出 ...

  7. USACO翻译:USACO 2013 NOV Silver三题

    USACO 2013 NOV SILVER 一.题目概览 中文题目名称 未有的奶牛 拥挤的奶牛 弹簧牛 英文题目名称 nocow crowded pogocow 可执行文件名 nocow crowde ...

  8. USACO翻译:USACO 2013 DEC Silver三题

    USACO 2013 DEC SILVER 一.题目概览 中文题目名称 挤奶调度 农场航线 贝西洗牌 英文题目名称 msched vacation shuffle 可执行文件名 msched vaca ...

  9. USACO翻译:USACO 2014 DEC Silver三题

    USACO 2014 DEC SILVER 一.题目概览 中文题目名称 回程 马拉松 奶牛慢跑 英文题目名称 piggyback marathon cowjog 可执行文件名 piggyback ma ...

随机推荐

  1. 转:关于VS2012连接MySql数据库时无法选择数据源

    原文来自 http://www.cnblogs.com/sanduo8899/p/3698617.html 您的C#开发工具是用VS2012吗?     No! return;     您的数据库用的 ...

  2. Hadoop(HA)分布式集群部署

    Hadoop(HA)分布式集群部署和单节点namenode部署其实一样,只是配置文件的不同罢了. 这篇就讲解hadoop双namenode的部署,实现高可用. 系统环境: OS: CentOS 6.8 ...

  3. winform 用户控件事件的写法

    public partial class UcTest : UserControl { public UcTest() { InitializeComponent(); } //定义事件 public ...

  4. Jedis客户端操作redis缓存命令详解

    1.对value操作的命令 exists(key):确认一个key是否存在 del(key):删除一个key type(key):返回值的类型 keys(pattern):返回满足给定pattern的 ...

  5. 决策树之Cart算法一

    Contents    1. CART算法的认识    2. CART算法的原理    3. CART算法的实现 1. CART算法的认识 Classification And Regression ...

  6. Microsoft Word 2010/2013 无法创建工作文件 请检查临时环境变量

    解决方案:重置IE缓存文件夹

  7. Linq 查询某个字段为null的数据

    如tb_flag 数据结构如下:flag int null 不能使用:flag==null 生成的SQL语句为 where flag=null   建议使用:可空类型 用Nullable<T&g ...

  8. 《构建高性能web站点》读书笔记:CPU/IO并发策略

    服务器并发处理能力:单位时间内处理的请求数,吞吐率,reqs/s apache的mod_status,显示的 requests/sec,从启动开始的平均计算值.lighttpd的mod_status显 ...

  9. jenkins 忘记admin用户账号密码

    一不小心,忘记了admin用户的账号密码.然后就看不到manage jenkins的那部分内容了,看不到就改不了用户权限,也就是系统瘫痪了. 于是,想着开始没注册账号和密码的时候,都能看见,也就是没有 ...

  10. redis的其他命令

    1.del del key-name 用于删除已存在的键.不存在的 key 会被忽略 返回值:被删除 key 的数量 2.DUMP DUMP key-name 用于序列化给定 key ,并返回被序列化 ...