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. 5 Kafka 应用问题经验积累

    16.Kafka 配置文件同步 为了给kafka的进程添加GC日志信息,方便在以后重启的时候,加入GC日志: 修改bin/kafka-server-start.sh: export KAFKA_OPT ...

  2. elk定时清理日志

    #!/bin/bash shijian=`date +%Y.%m.%d -d "5 days ago"` #echo $shijian curl -XDELETE "10 ...

  3. CF&&CC百套计划2 CodeChef December Challenge 2017 Chef and Hamming Distance of arrays

    https://www.codechef.com/DEC17/problems/CHEFHAM #include<cstdio> #include<cstring> #incl ...

  4. Git之版本回退及回滚

    应用场景 当开发某个项目时,会有多次提交记录,如A版本àB版本àC版本,假如目前处于C版本状态,我想回退到A版本,该如何操作:而当回退到A版本后,我又想回滚到B版本,又该如何操作,见下文分解!

  5. Eclipse使用小结

    一.Eclipse新建工作空间设置默认编码格式UTF-8 1.windows->Preferences...打开"首选项"对话框,左侧导航树,导航到general->W ...

  6. 令assignment操作符返回一个reference to *this

    [令assignment操作符返回一个reference to *this] 关于赋值,可以把它们写成连锁形式: int x, y, z; x =y =z =15; II赋值连锁形式 上述连锁赋值被解 ...

  7. 数据库日志文件(databasename_log.ldf)太大 如何清除

    在SQL2008中清除日志就必须在简单模式下进行,等清除动作完毕再调回到完全模式.方案一:完全命令模式USE[master] GO ALTER DATABASE DNName SET RECOVERY ...

  8. 简单几招,解决jQuery.getJSON的缓存问题

    今天做测试工作,发现了一个令我费解的问题,jquery的getJson方法在firefox上运行可以得到返回的结果,但是在ie8上测试,竟发现没有发送请求,故不能取到任何返回的结果,经历了一翻周折,找 ...

  9. Strusts2笔记4--类型转换器

    类型转换器: Struts2默认情况下可以将表单中输入的文本数据转换为相应的基本数据类型.这个功能的实现,主要是由于Struts2内置了类型转换器.这些转换器在struts-default.xml中可 ...

  10. C++ 和 MFC的学习

    1. 在Windows应用程序设计中,既可以使用个C的基本数据类型,也可以使用Windows自定义的数据类型.但要注意,凡是Windows自定义的关键字都要大写. 2. 什么是句柄? 在Windows ...