2013
11-26

Quoit Design

Have you ever played quoit in a playground? Quoit is a game in which flat rings are pitched at some toys, with all the toys encircled awarded.
In the field of Cyberground, the position of each toy is fixed, and the ring is carefully designed so it can only encircle one toy at a time. On the other hand, to make the game look more attractive, the ring is designed to have the largest radius. Given a configuration of the field, you are supposed to find the radius of such a ring.

Assume that all the toys are points on a plane. A point is encircled by the ring if the distance between the point and the center of the ring is strictly less than the radius of the ring. If two toys are placed at the same point, the radius of the ring is considered to be 0.

The input consists of several test cases. For each case, the first line contains an integer N (2 <= N <= 100,000), the total number of toys in the field. Then N lines follow, each contains a pair of (x, y) which are the coordinates of a toy. The input is terminated by N = 0.

For each test case, print in one line the radius of the ring required by the Cyberground manager, accurate up to 2 decimal places.

2
0 0
1 1
2
1 1
1 1
3
-1.5 0
0 0
0 1.5
0

0.71
0.00
0.75

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define esp 1e-6
using namespace std;
struct point
{
double x,y;
}p[100010];
int px[100010],py[100010],ty[100010];
int cmpx(const point &a,const point &b)
{
return a.y<b.y;
}
int cmpy(const int &a,const int &b)
{
return p[a].x<p[b].x;
}
inline double min(double a,double b)
{
return a<b?a:b;
}
inline double dist2(point &a,point &b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
double min_dis = 1e100;
double mindist(int* X,int *Y,int size)
{
if(size<=3)
{
if(size==2)
return dist2(p[X[0]],p[X[1]]);
for(int i=0; i<size; i++)
min_dis = min(min_dis,dist2(p[X[i]],p[X[(i+1)%size]]));
return min_dis;
}
int pl = (size+1)/2;
int pr = size - pl;
int l1 = 0,l2=pl;
for(int i=0; i<size; i++)
if(Y[i]<X[pl])
ty[l1++] = Y[i];
else ty[l2++] = Y[i];
for(int i=0; i<size; i++)
Y[i] = ty[i];
min_dis = min(mindist(&X[0],&Y[0],pl),mindist(&X[pl],&Y[pl],pr));
l1 = 0;
for(int i=0; i<size; i++)
if((p[Y[i]].x-p[X[pl-1]].x)*(p[Y[i]].x-p[X[pl-1]].x)<=min_dis)
ty[l1++] = Y[i];
for(int i=0; i<l1; i++)
for(int j=1; j<6&&i+j<l1; j++)
if((ty[i]-X[pl])*(ty[i+j]-X[pl])<=0)
min_dis = min(min_dis,dist2(p[ty[i]],p[ty[i+j]]));
return min_dis;
}

int main()
{
int n;
for(int i=0; i<100010; i++)
px[i] = i;
while(scanf("%d",&n)&&n)
{
for(int i=0; i<n; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
py[i] = i;
}
sort(p,p+n,cmpx);
sort(py,py+n,cmpy);
min_dis = 1e100;
printf("%.2lf\n",sqrt(mindist(px,py,n))/2);
}
return 0;
}

1. 约瑟夫也用说这么长……很成熟的一个问题了，分治的方法解起来o(n)就可以了，有兴趣可以看看具体数学的第一章，关于约瑟夫问题推导出了一系列的结论，很漂亮

2. #include <cstdio>
#include <cstring>

const int MAXSIZE=256;
//char store[MAXSIZE];
char str1[MAXSIZE];
/*
void init(char *store) {
int i;
store['A']=’V', store['B']=’W',store['C']=’X',store['D']=’Y',store['E']=’Z';
for(i=’F';i<=’Z';++i) store =i-5;
}
*/
int main() {
//freopen("input.txt","r",stdin);
//init(store);
char *p;
while(fgets(str1,MAXSIZE,stdin) && strcmp(str1,"STARTn")==0) {
if(p=fgets(str1,MAXSIZE,stdin)) {
for(;*p;++p) {
//*p=store[*p]
if(*p<’A’ || *p>’Z') continue;
if(*p>’E') *p=*p-5;
else *p=*p+21;
}
printf("%s",str1);
}
fgets(str1,MAXSIZE,stdin);
}
return 0;
}