usaco 1.5.2 The Clocks
2012-02-24 19:52
471 查看
麻麻说,如果研究了三天还是不会做的话,就算了吧。恩。
The Clocks
IOI'94 - Day 2
Consider nine clocks arranged in a 3x3 array thusly:
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.
[But this might or might not be the `correct' answer; see below.]
(e.g., 5 2 4 6 < 9 3 1 1).
此题大概提交了十几次。备份了三个。再加上拷别人的标答。刷新了做usaco题的悲剧记录。
到目前为止对题解的神展开理解不能。
就……就这样吧……
悲剧的只过了两组数据的bfs:
干!还特地去研究了优先队列了呢(虽然以前也做到过,但这次第一次是排自己写的结构啊)。难道是东西太多队列满了- -?烦烦烦烦烦。
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 accoring 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
此题大概提交了十几次。备份了三个。再加上拷别人的标答。刷新了做usaco题的悲剧记录。
到目前为止对题解的神展开理解不能。
就……就这样吧……
悲剧的只过了两组数据的bfs:
/* ID: wtff0411 PROG: clocks LANG: C++ */ #include <iostream> #include <fstream> #include <string> #include <cstring> #include <vector> #include <cmath> #include <queue> using namespace std; char ans[100]; long long move[10]={0,18911232,19136512, 2363904, 16810048, 2134536, 262657, 36936, 73, 4617}; struct p{ friend bool operator <(p x,p y) { return strcmp(x.res,y.res)>0; } long long num; char res[100]; }; priority_queue <p> q; void solve(int n) { p pp; pp.num=n; int i; int j=10000; pp.res[0]='0'; q.push(pp); while(1) { //cout<<q.top().num<<endl; if(q.top().num==0) system("pause"); p t=q.top(); q.pop(); if(t.num==0) { strcpy(ans,t.res); return ; } for(i=1;i<10;i++) { p tt; tt.num=(t.num+move[i])&57521883; strcpy(tt.res,t.res); tt.res[0]++; tt.res[tt.res[0]-'0']=i+'0'; q.push(tt); } } } int main() { //freopen("clocks.in","r",stdin); //freopen("clocks.out","w",stdout); int i,j; int input; memset(ans,'0',sizeof(ans)); int origin=0; for(i=8;i>=0;i--) { cin>>input; origin+=((input/3)%4)*(int)pow(8.0,i); } solve(origin); /*int num; for(i=1;;i*=10) if(res/i==0) {i=i/10;break;} for(;i>=10;i/=10) { cout<<res/i<<" "; res%=i; } cout<<res;*/ // cout<<ans; for(i=1;i<ans[0]-'0';i++) { cout<<ans[i]<<" "; } cout<<ans[i]; cout<<endl; system("pause"); return 0; }
干!还特地去研究了优先队列了呢(虽然以前也做到过,但这次第一次是排自己写的结构啊)。难道是东西太多队列满了- -?烦烦烦烦烦。
相关文章推荐
- 【USACO 1.5.2】回文质数
- USACO 1.4 The Clocks
- Usaco 1.5.2 回文质数(Prime Palindromes)
- USACO 1.4 The Clocks (clocks)
- usaco 1.4 The Clocks(暴搜)and poj 1166
- USACO1.4.2(The clocks)BFS
- USACO1.5.2 Prime Palindromes (pprime)
- USACO 1.5.2 Prime Palindromes 回文质数
- USACO6.5.4 The Clocks(clocks)
- USACO 1.4.2 The Clocks(DFS)
- usaco 1.5.2 pprime
- USACO1.5.2 Prime Palindromes (pprime)
- 1254. 【USACO题库】1.5.2 Prime Palindromes回文质数 (Standard IO)
- USACO:1.4.2 The Clocks 时钟(IOI 94) 解析
- USACO 1.4-The Clocks
- USACO 6.5 The Clocks
- USACO 1.4 The Clocks(枚举)
- [USACO 6.5.4]The Clocks
- 【宽搜】The Clocks 时钟 (Usaco_Training 1.4)
- usaco 1.5.2