USACO 6.5 The Clocks
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的更多相关文章
- USACO 完结的一些感想
其实日期没有那么近啦……只是我偶尔还点进去造成的,导致我没有每一章刷完的纪念日了 但是全刷完是今天啦 讲真,题很锻炼思维能力,USACO保持着一贯猎奇的题目描述,以及尽量不用高级算法就完成的题解……例 ...
- 【USACO】clocks 遇到各种问题 最后还是参考别人的思路
//放在USACO上一直通不过 不知道哪里出了问题 输出的n总是等于1 但是BFS递归的次数是对的 <----这个问题解决了 局部变量压入queue中返回就是对的了 #include<io ...
- USACO The Clocks
操作间没有次序关系,同一个操作最多重复3次... 可以直接暴力... The Clocks IOI'94 - Day 2 Consider nine clocks arranged in a 3x3 ...
- USACO chapter1
几天时间就把USACO chapter1重新做了一遍,发现了自己以前许多的不足.蒽,现在的程序明显比以前干净很多,而且效率也提高了许多.继续努力吧,好好的提高自己.这一章主要还是基本功的训练,没多少的 ...
- 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 ...
- 【USACO 3.1】Stamps (完全背包)
题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出 ...
- USACO翻译:USACO 2013 NOV Silver三题
USACO 2013 NOV SILVER 一.题目概览 中文题目名称 未有的奶牛 拥挤的奶牛 弹簧牛 英文题目名称 nocow crowded pogocow 可执行文件名 nocow crowde ...
- USACO翻译:USACO 2013 DEC Silver三题
USACO 2013 DEC SILVER 一.题目概览 中文题目名称 挤奶调度 农场航线 贝西洗牌 英文题目名称 msched vacation shuffle 可执行文件名 msched vaca ...
- USACO翻译:USACO 2014 DEC Silver三题
USACO 2014 DEC SILVER 一.题目概览 中文题目名称 回程 马拉松 奶牛慢跑 英文题目名称 piggyback marathon cowjog 可执行文件名 piggyback ma ...
随机推荐
- Hadoop基础-Hadoop快照管理
Hadoop基础-Hadoop快照管理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.快照的作用 快照可以迅速对文件(夹)进行备份,不产生新文件,使用差值存储,默认是禁用状态. ...
- asp.net webapi http请求生命周期
先附上webapi http生命周期图. 原始的图片地址为:https://www.asp.net/media/4071077/aspnet-web-api-poster.pdf
- bzoj千题计划134:bzoj3124: [Sdoi2013]直径
http://www.lydsy.com/JudgeOnline/problem.php?id=3124 第一问: dfs1.dfs2 dfs2中记录dis[i]表示点i距离最长链左端点的距离 第二问 ...
- android 水波纹效果实现
1.在drawable文件下,新建seletor,作为button的背景,这里我用的是两个圆角的shape <?xml version="1.0" encoding=&quo ...
- MySQL数据库远程连接很慢的解决方案
在开发机器上链接mysql数据库很慢,但是在数据库服务器上直接链接数据库很快.猜测应该是远程链接解析的问题,在查询MySQL相关文档和网络搜索后,发现了一个配置似乎可以解决这样的问题,就是在MySQL ...
- css 系统自学笔记2017-12-04
一.几个常用的可以连写的样式属性 1.backgroud: 背景连写:没有先后顺序,都是可选的. 2.font字体属性连写: font: 二.元素分类 块级元素:div p h1~h6 ul li o ...
- JavaScript实现单向链表
JavaScript 本身提供了十分好用的数据类型,以满足大家的日常使用.单靠 Array 和 Object 也的确足够应付日常的绝大部分需求,这也导致了很多前端er对数据结构这一块不是十分的了解. ...
- Web开发中的18个关键性错误
前几年,我有机会能参与一些有趣的项目,并且独立完成开发.升级.重构以及新功能的开发等工作. 本文总结了一些PHP程序员在Web开发中经常 忽略的关键错误,尤其是在处理中大型的项目上问题更为突出.典型的 ...
- CALayer的上动画的暂停和恢复
CHENYILONG Blog CALayer上动画的暂停和恢复 #pragma mark 暂停CALayer的动画-(void)pauseLayer:(CALayer*)layer{CFTimeIn ...
- sklearn_k均值聚类
# 机器学习之k均值聚类 # coding:utf-8 import sklearn.datasets as datasets from sklearn.cluster import KMeans i ...