2013
12-26

# Watchdog

A company (name withheld) has an office building in the center of Lund. The building has a perfectly square roof with a number of hatches. Because of a series of burglaries where the perpetrators have entered through these hatches, it was decided to use a watchdog to guard the hatches. A particularly vicious but rather stupid breed of dog was chosen, and unfortunately the dog fell off the roof on its third watch.

A new dog has been procured and it has been decided to attach a leash to its collar and attach the other end at some point on the roof. However, if the leash is too short the dog cannot reach all hatches, but if it is too long then the dog will fall off the building again. The leash has hooks at both ends, so no part of it is used to tie knots. The company wants the dog to reach the center of each hatch (the dog can reach exactly as far as the leash could reach if it were lying flat on the roof), but it does not want the leash to extend beyond the edge of the roof (to the edge is OK). They hope that by carefully choosing the length of the leash and where to attach it, the dog will be able to reach all hatches without risking falling off the building. A leash can only be attached at a point with integer coordinates (if the building is 10 by 10 meters, then the south-west corner of the building has coordinates (0, 0) and the north-east corner has coordinates (10, 10)). A leash cannot be attached at a point where there is a hatch.

If there is no place where you can attach a leash, reach all hatches but not reach beyond the edge of the roof, it is impossible to use this breed of dog, and the company will instead use a poodle (which is a less vicious type of dog, but also less prone to falling off buildings).

On the first line of the input is a single positive integer N, telling the number of test cases to follow. Each case starts with one line with two integers S H, where S is even, 2 <= S <= 40, and 1 <= H <= 50. S is the side of the square roof in meters and H is the number of hatches. The following H lines each contain two integers X and Y. These are the coordinates of the hatches. Hatches will never lie outside the roof or on the roof’s perimeter. No two hatches will occupy the same position

On the first line of the input is a single positive integer N, telling the number of test cases to follow. Each case starts with one line with two integers S H, where S is even, 2 <= S <= 40, and 1 <= H <= 50. S is the side of the square roof in meters and H is the number of hatches. The following H lines each contain two integers X and Y. These are the coordinates of the hatches. Hatches will never lie outside the roof or on the roof’s perimeter. No two hatches will occupy the same position

3
10 2
6 6
5 4
20 2
1 1
19 19
10 3
1 1
1 2
1 3

3 6
poodle
2 2

Description
A company (name withheld) has an office building in the center of Lund.

The building has a perfectly square roof with a number of hatches.

Because of a series of burglaries where the perpetrators have entered through these hatches,

it was decided to use a watchdog to guard the hatches.

A particularly vicious but rather stupid breed of dog was chosen, and unfortunately the dog fell off the roof on its third watch.

A new dog has been procured and it has been decided to attach a leash to its collar and attach the other end at some point on the roof.

However, if the leash is too short the dog cannot reach all hatches,

but if it is too long then the dog will fall off the building again.

The leash has hooks at both ends, so no part of it is used to tie knots.

The company wants the dog to reach the center of each hatch (the dog can reach exactly as far as the leash could reach if it were lying flat on the roof),

but it does not want the leash to extend beyond the edge of the roof (to the edge is OK).

They hope that by carefully choosing the length of the leash and where to attach it, the dog will be able to reach all hatches without risking falling off the building.

A leash can only be attached at a point with integer coordinates (if the building is 10 by 10 meters, then the south-west corner of the building has coordinates (0, 0) and the north-east corner has coordinates (10, 10)).

A leash cannot be attached at a point where there is a hatch.

If there is no place where you can attach a leash, reach all hatches but not reach beyond the edge of the roof, it is impossible to use this breed of dog, and the company will instead use a poodle (which is a less vicious type of dog, but also less prone to falling off buildings).

Input
On the first line of the input is a single positive integer N, telling the number of test cases to follow.

Each case starts with one line with two integers S H, where S is even, 2 <= S <= 40,and 1 <= H <= 50. S is the side of the square roof in meters and H is the number of hatches.

The following H lines each contain two integers X and Y.

These are the coordinates of the hatches.

Hatches will never lie outside the roof or on the roof's perimeter.

No two hatches will occupy the same position

Output
For each test case, output one line containing the coordinates X Y at which to fasten the leash

(if there are several possible points, output the one with smallest X, and if there are still several possibilities select the one with smallest Y among those with smallest X)
（如果有多个解，就输出X最小的，如果还是有多个解，就选择X最小中的Y最小的）
If there is no such point, output "poodle" for that test case.

#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<algorithm>

using namespace std;
typedef __int64 lld;
const int MAX=51;

const int INF=1000000001;
const double PI=acos(-1.0);
const double EPS=1.0e-8;
const int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
bool used[MAX][MAX];
struct Point
{
int x,y;
}p[MAX];
bool ok(int x,int y,int len,int n)
{
int i,tx,ty;
for(i=0;i<n;i++)
{
tx=x-p[i].x;
ty=y-p[i].y;
if(tx*tx+ty*ty>len)return false;
}
return true;
}
int main()
{
int n,m;
int T;
scanf("%d",&T);
while(T–)
{
scanf("%d%d",&n,&m);
memset(used,false,sizeof(used));
int i,j;
for(i=0;i<m;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
used[p[i].x][p[i].y]=true;
}

int ax=-1,ay=-1;
for(i=0;i<=n&&ax==-1;i++)
{
for(j=0;j<=n&&ax==-1;j++)
{
if(used[i][j])continue;
int len=i;
if(n-i<len)len=n-i;
if(j<len)len=j;
if(n-j<len)len=n-j;
if(ok(i,j,len*len,m))
{
ax=i;
ay=j;
}
}
}

if(ax!=-1)
{
printf("%d %d\n",ax,ay);
}
else puts("poodle");
}
return 0;
}
/*
3
10 2
6 6
5 4

20 2
1 1
19 19

10 3
1 1
1 2
1 3

*/

1. 作者加油啊，吾快没有耐心了，你也知道，这年头好看的小说不多的。虽说吾也是知道你更每更一次也是需要时间的，但吾还是求你快更啊，本人跪求啊！你如果再不更吾就一直跪着，你自己看着办吧！

2. 作者加油啊，吾快没有耐心了，你也知道，这年头好看的小说不多的。虽说吾也是知道你更每更一次也是需要时间的，但吾还是求你快更啊，本人跪求啊！你如果再不更吾就一直跪着，你自己看着办吧！

3. 作者加油啊，吾快没有耐心了，你也知道，这年头好看的小说不多的。虽说吾也是知道你更每更一次也是需要时间的，但吾还是求你快更啊，本人跪求啊！你如果再不更吾就一直跪着，你自己看着办吧！

4. 作者加油啊，吾快没有耐心了，你也知道，这年头好看的小说不多的。虽说吾也是知道你更每更一次也是需要时间的，但吾还是求你快更啊，本人跪求啊！你如果再不更吾就一直跪着，你自己看着办吧！

5. 作者加油啊，吾快没有耐心了，你也知道，这年头好看的小说不多的。虽说吾也是知道你更每更一次也是需要时间的，但吾还是求你快更啊，本人跪求啊！你如果再不更吾就一直跪着，你自己看着办吧！

6. 作者加油啊，吾快没有耐心了，你也知道，这年头好看的小说不多的。虽说吾也是知道你更每更一次也是需要时间的，但吾还是求你快更啊，本人跪求啊！你如果再不更吾就一直跪着，你自己看着办吧！

7. 作者加油啊，吾快没有耐心了，你也知道，这年头好看的小说不多的。虽说吾也是知道你更每更一次也是需要时间的，但吾还是求你快更啊，本人跪求啊！你如果再不更吾就一直跪着，你自己看着办吧！

8. 作者加油啊，吾快没有耐心了，你也知道，这年头好看的小说不多的。虽说吾也是知道你更每更一次也是需要时间的，但吾还是求你快更啊，本人跪求啊！你如果再不更吾就一直跪着，你自己看着办吧！

9. Good task for the group. Hold it up for every yeara??s winner. This is a excellent oppotunity for a lot more enhancement. Indeed, obtaining far better and much better is constantly the crucial. Just like my pal suggests on the truth about ab muscles, he just keeps obtaining much better.

10. Excellent Web-site! I required to ask if I might webpages and use a component of the net web website and use a number of factors for just about any faculty process. Please notify me through email regardless of whether that would be excellent. Many thanks

11. 第一句可以忽略不计了吧。从第二句开始分析，说明这个花色下的所有牌都会在其它里面出现，那么还剩下♠️和♦️。第三句，可以排除2和7，因为在两种花色里有。现在是第四句，因为♠️还剩下多个，只有是♦️B才能知道答案。

12. 第一句可以忽略不计了吧。从第二句开始分析，说明这个花色下的所有牌都会在其它里面出现，那么还剩下♠️和♦️。第三句，可以排除2和7，因为在两种花色里有。现在是第四句，因为♠️还剩下多个，只有是♦️B才能知道答案。