【BZOJ 4148】 4148: [AMPPZ2014]Pillars (乱搞)

4148: [AMPPZ2014]Pillars

Time Limit: 5 Sec  Memory Limit: 256 MBSec  Special Judge
Submit: 100  Solved: 49

Description

给定一个n*m的矩形,其中有f个2*2的障碍物,其中任意两个障碍物中心之间的欧几里得距离至少为6,
且每个障碍物的中心到边缘的距离至少为3。请找到一条从左下角(1,1)出发经过所有没有障碍物的点各
一次的且最后回到左下角的回路。

Input

第一行包含三个整数n,m,f(1<=n,m<=1000且n,m都为偶数)。
接下来f行,每行两个整数x,y(1<=x<n,1<=y<m),表示该障碍物左下角的坐标。

Output

如果无解,输出NIE,否则第一行输出TAK,第二行输出方案。
方案包含n*m-4*f个字符,第i个字符表示第i步的移动方向,用G表示上,D表示下,L表示左,P表示右。

Sample Input

12 6 2
3 3
9 3

Sample Output

TAK
PPPPPPPPPPPGGGLDDLLLLLGPPGLLLDDLLLGGGPPPPPPPPPPGLLLLLLLLLLLDDDDD

HINT

 

Source

 

【分析】

  唉。。乱搞的水题我都是不会。。

  就是随便弄一条路出来,然后绕开障碍。

  大概就是这样绕开:

  

  理解了好久。。

 

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 #include<iostream>
 5 #include<algorithm>
 6 using namespace std;
 7 
 8 char a[1010][1010];
 9 
10 int main()
11 {
12     int n,m,k;
13     scanf("%d%d%d",&n,&m,&k);
14     for(int i=1;i<=n;i++)
15      for(int j=1;j<=m;j++) a[i][j]=i&1?'D':'G';
16     for(int i=3;i<=n;i+=2) a[i][2]='L';
17     for(int i=2;i<=n;i+=2) a[i][m]='L';
18     for(int i=1;i<n;i++) a[i][1]='P';
19     for(int i=1;i<=k;i++)
20     {
21         int x,y;
22         scanf("%d%d",&x,&y);
23         if(x&1)
24         {
25             a[x+1][y-1]='L';
26             a[x][y+2]='P';
27             a[x+1][y+2]='P';
28             a[x+2][y+3]='L';
29         }
30         else
31         {
32             if(y==3)
33             {
34                 a[x][1]='G';
35                 a[x][2]='P';
36                 a[x+1][2]='D';
37                 a[x+1][y+2]='L';
38             }
39             else
40             {
41                 a[x+1][y+2]='L';
42                 a[x][y-1]='P';
43                 a[x+1][y-1]='P';
44                 a[x+2][y-2]='L';
45             }
46         }
47       }
48       printf("TAK\n");
49       int xx=1,yy=1,nw=n*m-4*k;
50       while(nw--)
51       {
52           printf("%c",a[xx][yy]);
53            if(a[xx][yy]=='L') xx--;
54           else if(a[xx][yy]=='P') xx++;
55           else if(a[xx][yy]=='D') yy--;
56           else yy++;
57       }
58     return 0;
59 }
View Code

 

2017-04-10 08:53:03

 

posted @ 2017-04-10 08:52  konjak魔芋  阅读(173)  评论(0编辑  收藏  举报