操作间没有次序关系,同一个操作最多重复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. php -- 取整数

    PHP取整数函数常用的四种方法,下面收集了四个函数: 经常用到取整的函数,今天小小的总结一下!其实很简单,就是几个函数而已--主要是:ceil,floor,round,intval ceil — 进一 ...

  2. 使用OpenSSL创建自己的CA root certificate

    在密码学中,CA(Certificate Authority,认证机构)是指一个被多个用户信任的机构,该机构能够创建和指派公钥证书. 为规范起见,我们先介绍本文可能涉及的术语, asymmetric ...

  3. List&Map&Set的操作和遍历

    Java的三大集合即:Set.List.Map. Set:代表无序.不可重复的集合,常用的有HashSet(哈希表实现).TreeSet(红黑树实现): List:代表有序.可以重复的集合,比较常用的 ...

  4. LoadRunner 使用介绍

    功能介绍 安装流程 LoadRunner是一款测试系统行为和性能的负债测试工具,通过模拟上千万用户实施并发复杂以实时性能监控的方式来确认和查找问题.它是一款付费商业软件,开发商为HP,个人开发者可以使 ...

  5. LinuxMint下tty.js的安装指南

    1.简介 tty.js是使用Node.js开发的开源Web-based SSH.通过浏览器即可远程访问shell. 关于Web-based SSH的介绍参考https://en.wikipedia.o ...

  6. 空基类优化—— EBCO—— empty base class optimization

    完全参考自:<C++ Templates The Complete Guide>e_CN,p_281 16.2 空基类优化 最近周围有点吵,论文没看进去,随便翻了本书…… 下文没有多大意义 ...

  7. 安装yeoman报没有权限的错误

    新的ubuntu服务器, 不小心先装了npm, 再装的node, 再用meanjs装的yeoman(即不是自己npm install -g yo装的, 是用meanjs的stack一步到位的),而正常 ...

  8. 用好这6个APP,学英语SO EASY!

      http://www.jianshu.com/p/30a27af18340  

  9. webdriver 日期控件的处理

    http://www.cnblogs.com/liu-ke/p/4200736.html http://blog.csdn.net/wanglha/article/details/44620627 h ...

  10. Android Studio使用技巧小记

    1.Android Studio中查看genymotion模拟器中的文件的方法: Tools-->Android Device Moniter 2.快速定位开源代码某功能的实现方法 右击项目-- ...