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

————————————————————————————————————题解
4^9果断暴搜
然后秒过……
用了一个指向函数的指针减少代码量
 /*
LANG: C++
PROG: clocks
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define siji(i,x,y) for(int i=(x) ; i <= (y) ; ++i)
#define xiaosiji(i,x,y) for(int i = (x) ; i < (y); ++i)
#define gongzi(j,x,y) for(int j = (x) ; j >= (y) ; --j)
#define ivorysi
#define mo 11447
#define eps 1e-8
#define o(x) ((x)*(x))
using namespace std;
typedef long long ll;
int clo[][],rec[],ans[],all=;
void span(int &a) {
a=(a+)%;
}
bool check() {
siji(i,,) {
siji(j,,) {
if(clo[i][j]!=)return false;
}
}
return true;
}
void del1() {
span(clo[][]);
span(clo[][]);
span(clo[][]);
span(clo[][]);
}
void del2() {
span(clo[][]);
span(clo[][]);
span(clo[][]);
}
void del3() {
span(clo[][]);
span(clo[][]);
span(clo[][]);
span(clo[][]);
}
void del4() {
span(clo[][]);
span(clo[][]);
span(clo[][]);
}
void del5() {
span(clo[][]);
span(clo[][]);
span(clo[][]);
span(clo[][]);
span(clo[][]);
}
void del6() {
span(clo[][]);
span(clo[][]);
span(clo[][]);
}
void del7() {
span(clo[][]);
span(clo[][]);
span(clo[][]);
span(clo[][]);
}
void del8() {
span(clo[][]);
span(clo[][]);
span(clo[][]);
}
void del9() {
span(clo[][]);
span(clo[][]);
span(clo[][]);
span(clo[][]);
}
void dfs(int dep,int times) {
if(times>=all) return;
if(dep>) {
if(!check()) return;
all=times;
memcpy(ans,rec,sizeof(rec));
return;
}
void (*cur)();
if(dep==) cur=&del1;
else if(dep==) cur=&del2;
else if(dep==) cur=&del3;
else if(dep==) cur=&del4;
else if(dep==) cur=&del5;
else if(dep==) cur=&del6;
else if(dep==) cur=&del7;
else if(dep==) cur=&del8;
else if(dep==) cur=&del9; siji(i,,) {
(*cur)();
rec[dep]=i;
dfs(dep+,times+i);
}
(*cur)();
rec[dep]=;
dfs(dep+,times);
}
void solve() {
siji(i,,) {
siji(j,,) {
scanf("%d",&clo[i][j]);
clo[i][j]/=;
--clo[i][j];
}
}
int cnt=;
dfs(,);
siji(i,,) {
siji(j,,ans[i]) {
++cnt;
printf("%d%c",i," \n"[cnt==all]);
}
}
}
int main(int argc, char const *argv[])
{
#ifdef ivorysi
freopen("clocks.in","r",stdin);
freopen("clocks.out","w",stdout);
#else
freopen("f1.in","r",stdin);
//freopen("f1.out","w",stdout);
#endif
solve();
return ;
}
 

USACO 6.5 The Clocks的更多相关文章

  1. USACO 完结的一些感想

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

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

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

  3. USACO The Clocks

    操作间没有次序关系,同一个操作最多重复3次... 可以直接暴力... The Clocks IOI'94 - Day 2 Consider nine clocks arranged in a 3x3 ...

  4. USACO chapter1

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

  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. python 多线程中的同步锁 Lock Rlock Semaphore Event Conditio

    摘要:在使用多线程的应用下,如何保证线程安全,以及线程之间的同步,或者访问共享变量等问题是十分棘手的问题,也是使用多线程下面临的问题,如果处理不好,会带来较严重的后果,使用python多线程中提供Lo ...

  2. python中的模块及路径(2)

    如果我们要添加自己的搜索目录,有两种方法: 一是直接修改sys.path,添加要搜索的目录: >>> import sys >>> sys.path.append( ...

  3. JAVA-JSP隐式对象

    JSP隐式对象 在本章中,我们将讨论和学习JSP中的隐式对象.这些对象是JSP容器为每个页面中的开发人员提供的Java对象,开发人员可以直接调用它们而不用显式地声明它们再调用. JSP隐式对象也称为预 ...

  4. 51nod1019 逆序数

    1019 逆序数 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为 ...

  5. [洛谷P3158] [CQOI2011]放棋子

    洛谷题目链接:[CQOI2011]放棋子 题目描述 在一个m行n列的棋盘里放一些彩色的棋子,使得每个格子最多放一个棋子,且不同 颜色的棋子不能在同一行或者同一列.有多少祌方法?例如,n=m=3,有两个 ...

  6. python 操作excel格式化及outlook正文,发送邮件

    import requests import time import os import arrow import pandas as pd import pandas.io.formats.exce ...

  7. [整理]SQL Server Reporting Services Charts

    http://msdn.microsoft.com/zh-cn/library/aa964128.aspx#mainSectionhttp://msdn.microsoft.com/en-us/lib ...

  8. Windows上安装QT4后更改MinGW的路径

    在windows上安装使用MinGW的QT4时,并不会一起安装MinGW. 在安装过程中,会让你指定已经安装的MinGW的路径. 当你使用QT4时,将使用你指定的MinGW的路径下的g++来编译构建程 ...

  9. 洛谷P3953 [NOIP2017]逛公园

    K<=50,感觉可以DP 先建反图求出从n到各个点的最短路,然后在正图上DP 设f[当前点][比最短路多走的距离]=方案数 转移显然是 $f[v][res]=\sum f[u][res+tmp] ...

  10. shutdown系统调用

    /* * Shutdown a socket. */ SYSCALL_DEFINE2(shutdown, int, fd, int, how) { int err, fput_needed; stru ...