版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/leekerian/article/details/81592320
这简直又是一道坑爹的题目,,,题意死活没看懂,,,,wa了我一天,,,
题意:object1 是6 是因为(1,6)构成的线段,(6,7)(7,1)这三条线段满足,取小是6
object2 (7,4)(4,6)(6,7)这三条线段满足所以为6,,,,
知道意思之后水题
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stdlib.h>
#include <string.h>
using namespace std;
const int maxn=111111;
const double eps=1e-8;
int sgn(double x)
{
if(fabs(x)<eps)
return 0;
if(x<0)
return -1;
else
return 1;
}
struct Point
{
double x,y;
int index;
Point(){}
Point(double _x,double _y)
{
x=_x;
y=_y;
}
Point operator -(const Point &b)const
{
return Point(x-b.x,y-b.y);
}
double operator ^(const Point &b)const
{
return x*b.y-y*b.x;
}
double operator *(const Point &b)const
{
return x*b.x+y*b.y;
}
};
struct Line
{
Point s,e;
Line(){};
Line(Point _s,Point _e)
{
s=_s;
e=_e;
}
};
Point p[maxn];
Point p1[maxn];
Point p3[maxn];
int check[maxn];
int cont;
double dist(Point a,Point b)
{
return sqrt((a-b)*(a-b));
}
bool cmp(Point a,Point b)
{
int ans=sgn((a-p[0])^(b-p[0]));
if(ans==1)
return true;
else if(ans==0)
return dist(a,p[0])<dist(b,p[0]);
else
return false;
}
int Stack[maxn];
int top;
void graham()
{
for(int i=0;i<cont;i++)
{
if(p[i].y<p[0].y||(p[i].y==p[0].y&&p[i].x<p[0].x))
swap(p[i],p[0]);
}
sort(p+1,p+cont,cmp);
Stack[0]=0;
Stack[1]=1;
top=2;
for(int i=2;i<cont;i++)
{
while(top>1&&((p[Stack[top-1]]-p[Stack[top-2]])^(p[i]-p[Stack[top-2]]))<=0)
top--;
Stack[top++]=i;
}
}
vector <Point> ve;
int main()
{
char str[100];
while(1)
{
gets(str);
if(strlen(str)==1&&str[0]=='#')
break;
Point p2;
double x,y;
ve.clear();
scanf("%lf %lf",&x,&y);
p2=Point(x,y);
cont=0;
while(1)
{
double x1,y1;
scanf("%lf %lf",&x1,&y1);
if(x1==0&&y1==0)
break;
p[cont]=Point(x1,y1);
p[cont].index=cont+1;
ve.push_back(p[cont]);
cont++;
}
for(int i=1;i<ve.size();i++)
{
if(sgn((ve[i-1]-ve[i])^(ve[(i+1)%ve.size()]-ve[i]))==0)
ve.erase(ve.begin()+i);
}
/*for(int i=0;i<ve.size();i++)
{
cout<<ve[i].x<<" "<<ve[i].y<<ve[i].index<<endl;
}*/
graham();
for(int i=0;i<top;i++)
{
p1[i]=p[Stack[i]];
p1[i].index=p[Stack[i]].index;
//cout<<p1[i].x<<" "<<p1[i].y<<" "<<p1[i].index<<endl;
}
int max1=1000000000;
for(int i=0;i<top;i++)
{
if(sgn((p1[i]-p2)^(p1[(i+1)%top]-p2))==1&&sgn((p2-p1[i])*(p1[(i+1)%top]-p1[i]))==1&&sgn((p2-p1[(i+1)%top])*(p1[i]-p1[(i+1)%top]))==1)
{
max1=min(max1,max(p1[i].index,p1[(i+1)%top].index));
}
}
printf("%s %d\n",str,max1);
getchar();
}
return 0;
}