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 ...
随机推荐
- Java基础-面向接口编程-JDBC详解
Java基础-面向接口编程-JDBC详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.JDBC概念和数据库驱动程序 JDBC(Java Data Base Connectiv ...
- JVM体系结构和工作方式
JVM能够跨计算机体系结构来执行Java字节码,主要是由于JVM屏蔽了与各个计算机平台相关的软件或者是硬件之间的差异,使得与平台相关的耦合统一由JVM提供者来实现. 何为JVM ...
- linux下yum错误:[Errno 14] problem making ssl connection Trying other mirror.
今天是要yum命令安装EPEL仓库后 yum install epel-release 突然发现yum安装其他的软件出错. 错误:[Errno 14] problem making ssl conne ...
- bzoj千题计划123:bzoj1027: [JSOI2007]合金
http://www.lydsy.com/JudgeOnline/problem.php?id=1027 因为x+y+z=1,所以z=1-x-y 第三维可以忽略 将x,y 看做 平面上的点 简化问题: ...
- (一)在Lingo中使用集合
1. 在Lingo中使用集合 4.1 集合的基本用法和lingo模型的基本要素 Lingo虽然使用方便,但是如果要解决几万个,几十万个变量的优化问题时,我们总不能一个一个地列出x1,x2,…,x ...
- Golang入门教程(一)GOPATH与工作空间(Windows)
https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/01.2.md Windows 环境: 下面我就 ...
- [洛谷P3643] [APIO2016]划艇
洛谷题目链接:[APIO2016]划艇 题目描述 在首尔城中,汉江横贯东西.在汉江的北岸,从西向东星星点点地分布着 \(N\) 个划艇学校,编号依次为 \(1\) 到 \(N\).每个学校都拥有若干艘 ...
- Mockserver -MOCO的使用
转自: http://blog.csdn.net/shensky711/article/details/52770686
- Java并发编程原理与实战三十八:多线程调度器(ScheduledThreadPoolExecutor)
在前面介绍了java的多线程的基本原理信息:线程池的原理与使用 本文对这个java本身的线程池的调度器做一个简单扩展,如果还没读过上一篇文章,建议读一下,因为这是调度器的核心组件部分. 我们如果要用j ...
- MongoDB - MongoDB CRUD Operations, Bulk Write Operations
Overview MongoDB provides clients the ability to perform write operations in bulk. Bulk write operat ...