usaco 4.4 Shuttle Puzzle 找规律
2008-08-25 16:23
211 查看
可以用宽搜尝试,结果n>9时发现严重超时,超空间。观察一下输出结果
n = 9
2: 9 11
3: 12 10 8
4: 7 9 11 13
5: 14 12 10 8 6
6: 5 7 9 11 13 15
7: 16 14 12 10 8 6 4
8: 3 5 7 9 11 13 15 17
9: 18 16 14 12 10 8 6 4 2
10: 1 3 5 7 9 11 13 15 17 19
9: 18 16 14 12 10 8 6 4 2
8: 3 5 7 9 11 13 15 17
7: 16 14 12 10 8 6 4
6: 5 7 9 11 13 15
5: 14 12 10 8 6
4: 7 9 11 13
3: 12 10 8
2: 9 11
1: 10
n = 8
2: 8 10
3: 11 9 7
4: 6 8 10 12
5: 13 11 9 7 5
6: 4 6 8 10 12 14
7: 15 13 11 9 7 5 3
8: 2 4 6 8 10 12 14 16
9: 17 15 13 11 9 7 5 3 1
8: 2 4 6 8 10 12 14 16
7: 15 13 11 9 7 5 3
6: 4 6 8 10 12 14
5: 13 11 9 7 5
4: 6 8 10 12
3: 11 9 7
2: 8 10
1: 9
很有规律,那么输出皆可~~
/*
PROG: shuttle
LANG: C++
ID: heben991
*/
#include <iostream>
#include <algorithm>
using namespace std;
const int M = 1000000;
int a[M];
int main()
{
int i, j, k, n, x, sign;
freopen("shuttle.in","r",stdin);
freopen("shuttle.out","w",stdout);
scanf("%d", &n);
sign = 1;
x = n;
for(i = 2; i <= n+1; ++i)
{
for(j = 1; j <= i; ++j)
{
a[++a[0]] = x;
if(j!=i) x += 2*sign;
else x += sign;
//printf("%d ", a[a[0]]);
}
//puts("");
sign *= -1;
}
x += 2*sign;
for(i = n; i >= 1; --i)
{
for(j = 1; j <= i; ++j)
{
a[++a[0]] = x;
if(j!=i) x += 2*sign;
else x -= sign;
//printf("%d ", a[a[0]]);
}
//puts("");
sign *= -1;
}
j = 0;
for(i = 1; i <= a[0]; ++i)
{
printf("%d",a[i]);
++j;
if(j==20 || i==a[0])
{
j = 0;
putchar('/n');
}
else putchar(' ');
}
return 0;
}
n = 9
2: 9 11
3: 12 10 8
4: 7 9 11 13
5: 14 12 10 8 6
6: 5 7 9 11 13 15
7: 16 14 12 10 8 6 4
8: 3 5 7 9 11 13 15 17
9: 18 16 14 12 10 8 6 4 2
10: 1 3 5 7 9 11 13 15 17 19
9: 18 16 14 12 10 8 6 4 2
8: 3 5 7 9 11 13 15 17
7: 16 14 12 10 8 6 4
6: 5 7 9 11 13 15
5: 14 12 10 8 6
4: 7 9 11 13
3: 12 10 8
2: 9 11
1: 10
n = 8
2: 8 10
3: 11 9 7
4: 6 8 10 12
5: 13 11 9 7 5
6: 4 6 8 10 12 14
7: 15 13 11 9 7 5 3
8: 2 4 6 8 10 12 14 16
9: 17 15 13 11 9 7 5 3 1
8: 2 4 6 8 10 12 14 16
7: 15 13 11 9 7 5 3
6: 4 6 8 10 12 14
5: 13 11 9 7 5
4: 6 8 10 12
3: 11 9 7
2: 8 10
1: 9
很有规律,那么输出皆可~~
/*
PROG: shuttle
LANG: C++
ID: heben991
*/
#include <iostream>
#include <algorithm>
using namespace std;
const int M = 1000000;
int a[M];
int main()
{
int i, j, k, n, x, sign;
freopen("shuttle.in","r",stdin);
freopen("shuttle.out","w",stdout);
scanf("%d", &n);
sign = 1;
x = n;
for(i = 2; i <= n+1; ++i)
{
for(j = 1; j <= i; ++j)
{
a[++a[0]] = x;
if(j!=i) x += 2*sign;
else x += sign;
//printf("%d ", a[a[0]]);
}
//puts("");
sign *= -1;
}
x += 2*sign;
for(i = n; i >= 1; --i)
{
for(j = 1; j <= i; ++j)
{
a[++a[0]] = x;
if(j!=i) x += 2*sign;
else x -= sign;
//printf("%d ", a[a[0]]);
}
//puts("");
sign *= -1;
}
j = 0;
for(i = 1; i <= a[0]; ++i)
{
printf("%d",a[i]);
++j;
if(j==20 || i==a[0])
{
j = 0;
putchar('/n');
}
else putchar(' ');
}
return 0;
}
相关文章推荐
- usaco 4.4 Shuttle Puzzle 2010.8.8
- USACO-Section 4.4 Shuttle Puzzle (BFS)
- USACO Section 4.4 Shuttle Puzzle - Hash都不用的DFS水题..
- USACO 4.4 Shuttle Puzzle(dfs)
- USACO 4.4 shuttle puzzle
- USACO 4.4 Shuttle Puzzle
- usaco 4.4 Shuttle Puzzle(字符hash+搜索)
- usaco 4.4 Pollutant Control(最小割最少边数字典序最小)
- 求割边最少的最小割(P1344 [USACO4.4]追查坏牛奶Pollutant Control)
- 规律好题——[Usaco2005 Jan]Moo Volume
- 找规律——[Usaco2005 Jan]Sumsets
- usaco 4.4 Frame Up(拓扑排序)
- 洛谷 P1344 [USACO4.4]追查坏牛奶Pollutant Control
- USACO Party Lamps 【Binary code solvution】【规律】
- usaco 4.4 Frame Up 2010.8.8
- USACO 4.4 Pollutant Control
- [USACO 4.4.1 Shuttle Puzzle]
- usaco 4.4.1 Shuttle Puzzle
- Shuttle Puzzle[USACO]
- usaco-4.4-shutter-passed