Description
Input
Output
Sample Input
2
2
0 0
1000 0
1000 1000
2000 1000
2
0 0
1000 0
2000 1000
2000 2000
Sample Output
happy
sad
HINT
题意:给出n+2点的坐标,看从1点能不能走到n+2点,要注意能走的最长距离不能超过1000,而且这个距离不是曼哈顿距离,假设两点是矩形的对角,不能走对角线,而必须走直角边
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct point
{
int x,y;
}a[105];
int vis[105],n;
int abs(int a)
{
if(a<0)
return -a;
return a;
}
void dfs(int src)
{
if(vis[src]) return;
vis[src] = 1;
for(int i = 0;i<n;i++)
{
if(abs(a[src].x-a[i].x)+abs(a[src].y-a[i].y)<=1000)
dfs(i);
}
}
int main()
{
int t,i;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
n = n+2;
for(i = 0;i<n;i++)
scanf("%d%d",&a[i].x,&a[i].y);
memset(vis,0,sizeof(vis));
dfs(0);
if(vis[n-1])
printf("happy\n");
else
printf("sad\n");
}
return 0;
}