USACO 4.4 shuttle puzzle
2012-01-23 21:01
363 查看
起初用搜索,写了好多,bfs+位运算。。。然后STL的队列给MLE了。。。但是算出的结果是正确的,然后接着是TLE。。。
虽然用搜索没有挂,但是不得不说又练了一下代码能力,还是有不少收获的,呵呵。。
正确的算法是找规律,详细的做法看nocow吧,这里贴个代码:
搜索:
View Code
虽然用搜索没有挂,但是不得不说又练了一下代码能力,还是有不少收获的,呵呵。。
正确的算法是找规律,详细的做法看nocow吧,这里贴个代码:
搜索:
View Code
/* ID: zlqest11 LANG: C++ TASK: shuttle */ #include <iostream> #include <cstdio> #include <cstring> using namespace std; int n, ct, table[500], ans[500]; int main() { freopen("shuttle.in", "r", stdin); freopen("shuttle.out", "w", stdout); scanf("%d", &n); if(n == 1) printf("1 3 2\n"); else{ ct = 0; if(n & 1){ for(int i = 3; i <= n; i += 2){ table[++ct] = 1; for(int j = 1; j < i; j++) table[++ct] = -2; table[++ct] = -1; for(int j = 1; j <= i; j++) table[++ct] = 2; } for(int i = ct-n; i > 0; i--) table[++ct] = table[i]; } else{ for(int i = 2; i <= n; i += 2){ table[++ct] = 1; for(int j = 1; j <= i; j++) table[++ct] = -2; if(i == n) break; table[++ct] = -1; for(int j = 1; j <= i+1; j++) table[++ct] = 2; } for(int i = ct-n; i > 0; i--) table[++ct] = table[i]; } //for(int i = 1; i <= ct; i++) printf("%d ", table[i]); //printf("\n"); int tail = 0; ans[++tail] = n; ans[++tail] = ans[tail-1]+2; for(int i = 1; i <= ct; i++) ans[++tail] = ans[tail-1] + table[i]; ans[++tail] = ans[tail-1] + 2; ans[++tail] = ans[tail-1] - 1; for(int i = 1; i <= tail; i++){ if(i%20 != 1) putchar(' '); printf("%d", ans[i]); if(i%20 == 0) printf("\n"); } if(tail%20 != 0) printf("\n"); } return 0; }
相关文章推荐
- USACO 4.4 Shuttle Puzzle
- usaco 4.4 Shuttle Puzzle 找规律
- usaco 4.4 Shuttle Puzzle(字符hash+搜索)
- usaco 4.4 Shuttle Puzzle 2010.8.8
- USACO-Section 4.4 Shuttle Puzzle (BFS)
- USACO 4.4 Shuttle Puzzle(dfs)
- USACO Section 4.4 Shuttle Puzzle - Hash都不用的DFS水题..
- usaco 4.4.1 Shuttle Puzzle
- usaco-4.4-shutter-passed
- USACO 4.4 Pollutant Control
- USACO 4.4 Frame Up(拓扑排序)
- 求割边最少的最小割(P1344 [USACO4.4]追查坏牛奶Pollutant Control)
- USACO Section 4.4 Shuttle Puzzle
- USACO Shuttle Puzzle 解题报告
- [USACO 4.4.1 Shuttle Puzzle]
- P1344 [USACO4.4] 追查坏牛奶Pollutant Control
- USACO 4.4 Pollutant Control
- 08-27~29 HDU1010 USACO4.3~4.4 搜索剪枝,模拟,拓扑,网络流
- Shuttle Puzzle[USACO]
- C++——【USACO 4.4.1】——Shuttle Puzzle