操作间没有次序关系,同一个操作最多重复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. 如何使用Matrix对bitmap的旋转与镜像水平垂直翻转

    Bitmap convert(Bitmap a, int width, int height){int w = a.getWidth();int h = a.getHeight();Bitmap ne ...

  2. Websphere多个应用session相互覆盖问题解决办法

    原文链接:http://my.oschina.net/moyuqi/blog/98475 使用apache反向代理解决在应用A使用Iframe嵌入应用B的功能而产生的跨域问题后,应用B的功能能正常使用 ...

  3. VS 附加进程调试 Web项目

    一.新建IIS站点物理路径要指定项目开发Web路径(不可以发布), 二.Host文件网站域名要指定127.0.0.1 三.打开项目目录找到.vs\config\applicationhost.conf ...

  4. js eventLoop (使用chunk 同步变异步)

    https://www.cnblogs.com/xiaohuochai/p/8527618.html 线程 javascript是单线程的语言,也就是说,同一个时间只能做一件事.而这个单线程的特性,与 ...

  5. Fedora 安装oracle11g 之最简洁方式

    最新的Fedora 24已经释出. 赶紧尝试安装oracle11g一把.很简单,很方便. 此处以最最简洁方式来安装一把! 环境: windows xp + virtualbox ,安装 fedora ...

  6. Java时间日期字符串格式转换大全

    import java.text.*; import java.util.Calendar; public class VeDate { /** * 获取现在时间 * * @return 返回时间类型 ...

  7. mysql对执行结果进行html格式的输出?输出html格式?

    需求描述: 在执行mysql命令的时候,有的时候需要将查询的结果输出到文件,如果想要html格式的,应该怎么输出, 在此记录下操作的过程. 1.通过tee命令结合--html输出查询结果到html文件 ...

  8. PHP导出excel文件的几种方式

    PHP导出excel文件的几种方式 先说说动态生成的内容当作文件来下载的方法: 1.通过把Content-Type设置为application/octet-stream,可以把动态生成的内容当作文件来 ...

  9. SpringBoot自动配置xxxAutoConfiguration 的使用

    https://sdqali.in/blog/2016/07/16/controlling-redis-auto-configuration-for-spring-boot-session/ 常用的类 ...

  10. error:undefined reference to 'net_message_processor::net_message_processor()'

    net_message_processor是我自己定义的一个类,文件名称分别是net_message_processor.h  & net_message_processor.cpp 和CCD ...