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 ...
随机推荐
- Spring Boot的属性加载顺序
伴随着团队的不断壮大,往往不需要开发人员知道测试或者生产环境的全部配置细节,比如数据库密码,帐号信息等.而是希望由运维或者指定的人员去维护配置信息,那么如果要修改某项配置信息,就不得不去修改项 ...
- Openssh版本升级(Centos6.7)
实现前提公司服务器需要进行安全测评,扫描漏洞的设备扫出了关于 openssh 漏洞,主要是因为 openssh的当前版本为5.3,版本低了,而yum最新的openssh也只是5.3,没办法只能到 rp ...
- Linux 常见文件及目录
文件/etc//etc/passwd用户基本信息/etc/group用户组基本信息/etc/shadow/etc/passwd 文件的补充/etc/gshadow阴影口令套组中的组配置文件/etc/l ...
- soj1564. HOUSING
1564. HOUSING Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description For the Youth Olympic ...
- [csp-201403-3]命令行选项
#include<bits/stdc++.h> //#include <sstream> // if want to use stringstream using namesp ...
- sklearn进行拟合
# codind:utf-8 from sklearn.linear_model import SGDRegressor,LinearRegression,Ridge from sklearn.pre ...
- 关于app的cpu占用率想到的几个问题
1.top 命令获取的cpu是手机瞬间的cpu 2.dumpsys获取的是一段时间cpu的平均值?那么这段时间是指哪段,从哪开始到什么时候结束? 3.如果想测试app某操作下的cpu占用情况时候.应该 ...
- python实现单单链表
# -*- coding: utf-8 -*- # @Time : 2018/9/28 22:09 # @Author : cxa # @File : node.py # @Software: PyC ...
- iOS 里const在修饰对象时候的用法
玩iOS的小伙伴对const应该很不陌生, 在声明全局常量的时候很多时候都会用到, 但是有时候修饰对象很迷惑下面是个人总结, 下面的地址都是模拟的 1. const NSString *str1 = ...
- 004_MAC实用的小工具
一.XtraFinder(右键菜单扩展) http://www.xuebuyuan.com/173454.html http://www.mamicode.com/info-detail-111618 ...