Submission #3708280
Source Code Expand
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;
const double eps=1e-6;
int N,top;
struct node
{
double x,y;
};
node n[100005],dot[100005];
double dis(node a,node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double S(node a,node b,node c)
{
node X,Y;
X.x=b.x-a.x;
X.y=b.y-a.y;
Y.x=c.x-a.x;
Y.y=c.y-a.y;
return fabs(X.x*Y.y-X.y*Y.x);
}
bool my_comp(node a,node b)
{
double X=(a.x-n[1].x)*(b.y-n[1].y);
double Y=(a.y-n[1].y)*(b.x-n[1].x);
double Z=X-Y;
if(fabs(Z)<=eps)
if(dis(n[1],a)<dis(n[1],b)) return true;
else return false;
else
return Z>0?true:false;
}
void init()
{
int i;
scanf("%d",&N);
for(i=1;i<=N;++i) scanf("%lf%lf",&n[i].x,&n[i].y);
}
bool ok(int i)
{
double X=(dot[top].x-dot[top-1].x)*(n[i].y-dot[top-1].y);
double Y=(dot[top].y-dot[top-1].y)*(n[i].x-dot[top-1].x);
if(X-Y<eps) return true;
else return false;
}
void graham()
{
int i,j;
for(i=2;i<=N;++i)
if(n[i].y-n[1].y<eps||fabs(n[i].y-n[1].y)<eps&&n[i].x-n[1].x<eps)
{
swap(n[i].x,n[1].x);
swap(n[i].y,n[1].y);
}
sort(n+2,n+N+1,my_comp);
dot[0]=n[1],dot[1]=n[2];
top=1;
for(i=3;i<=N;++i)
{
while(top>0&&ok(i)) --top;
dot[++top]=n[i];
}
}
double rotate()
{
double ret=0.0;
int i,j;
j=2;++top;
for(i=0;i<top;++i)
{
while(S(dot[i],dot[(i+1)%top],dot[j])<S(dot[i],dot[(i+1)%top],dot[(j+1)%top]))
j=(j+1)%top;
ret=max(ret,dis(dot[j],dot[i]));
ret=max(ret,dis(dot[j],dot[(i+1)%top]));
}
return ret;
}
int main()
{
// freopen("dotfar.in","r",stdin);
// freopen("dotfar.out","w",stdout);
init();
graham();
printf("%.6lf\n",rotate());
fclose(stdin);
fclose(stdout);
return 0;
}
Submission Info
Compile Error
./Main.cpp: In function ‘void init()’:
./Main.cpp:48:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&N);
^
./Main.cpp:49:51: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
for(i=1;i<=N;++i) scanf("%lf%lf",&n[i].x,&n[i].y);
^
Judge Result
Set Name |
All |
Score / Max Score |
100 / 100 |
Status |
|
Set Name |
Test Cases |
All |
00_max.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 00_sample_05.txt, 01_rnd_00.txt, 01_rnd_01.txt, 01_rnd_02.txt, 01_rnd_03.txt, 01_rnd_04.txt, 01_rnd_05.txt, 01_rnd_06.txt, 01_rnd_07.txt, 01_rnd_08.txt, 01_rnd_09.txt, 01_rnd_10.txt, 01_rnd_11.txt, 01_rnd_12.txt, 01_rnd_13.txt, 01_rnd_14.txt, 01_rnd_15.txt, 01_rnd_16.txt, 01_rnd_17.txt, 01_rnd_18.txt, 01_rnd_19.txt |
Case Name |
Status |
Exec Time |
Memory |
00_max.txt |
AC |
1 ms |
256 KB |
00_sample_01.txt |
AC |
1 ms |
256 KB |
00_sample_02.txt |
AC |
1 ms |
256 KB |
00_sample_03.txt |
AC |
1 ms |
256 KB |
00_sample_04.txt |
AC |
1 ms |
256 KB |
00_sample_05.txt |
AC |
1 ms |
256 KB |
01_rnd_00.txt |
AC |
1 ms |
256 KB |
01_rnd_01.txt |
AC |
1 ms |
256 KB |
01_rnd_02.txt |
AC |
1 ms |
256 KB |
01_rnd_03.txt |
AC |
1 ms |
256 KB |
01_rnd_04.txt |
AC |
1 ms |
256 KB |
01_rnd_05.txt |
AC |
1 ms |
256 KB |
01_rnd_06.txt |
AC |
1 ms |
256 KB |
01_rnd_07.txt |
AC |
1 ms |
256 KB |
01_rnd_08.txt |
AC |
1 ms |
256 KB |
01_rnd_09.txt |
AC |
1 ms |
256 KB |
01_rnd_10.txt |
AC |
1 ms |
256 KB |
01_rnd_11.txt |
AC |
1 ms |
256 KB |
01_rnd_12.txt |
AC |
1 ms |
256 KB |
01_rnd_13.txt |
AC |
1 ms |
256 KB |
01_rnd_14.txt |
AC |
1 ms |
256 KB |
01_rnd_15.txt |
AC |
1 ms |
256 KB |
01_rnd_16.txt |
AC |
1 ms |
256 KB |
01_rnd_17.txt |
AC |
1 ms |
256 KB |
01_rnd_18.txt |
AC |
1 ms |
256 KB |
01_rnd_19.txt |
AC |
1 ms |
256 KB |