Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 7175 | Accepted: 2946 |
Description
Input
Output
Sample Input
7 20 0 37 100 40 0 76 100 85 0 0 75 100 90 0 90 0 71 100 61 0 14 100 38 100 47 47 100 54.5 55.4
Sample Output
Number of doors = 2
题意:
求需要最少破多少墙才能出去(每次破墙要求这么面墙是当前房间的正中间)
转化:
枚举正方形边上的每一个小线段的终点到目的地的连线,可以与多少内部线段相交,再加上一(最外围的墙)
#include
#include
#include
#include
using namespace std;
#define MAXN 100
struct point
{
double x,y;
point(){}
point(double _x,double _y){
x=_x,y=_y;
}
};
point P1[MAXN],P2[MAXN];
int k1,k2,k3,k4;
point left[MAXN],right[MAXN],up[MAXN],down[MAXN];
double Dis(point p1,point p2){
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
double Cross(point p1,point p2,point p3){
return (p2.x-p1.x)*(p3.y-p1.y)-(p2.y-p1.y)*(p3.x-p1.x);
}
point operator - (point A,point B){
return point(A.x-B.x, A.y-B.y);
}
point operator + (point A, point B){
return point(A.x+B.x, A.y+B.y);
}
point operator * (point A, double p){
return point(A.x*p, A.y*p);
}
bool operator == (point A, point B){
return (A.x-B.x) == 0 && (A.y-B.y) == 0;
}
bool SegmentProperIntersection(point a,point b,point c,point d)
{
return (max(a.x,b.x)>=min(c.x,d.x))&&
(max(c.x,d.x)>=min(a.x,b.x))&&
(max(a.y,b.y)>=min(c.y,d.y))&&
(max(c.y,d.y)>=min(a.y,b.y))&&
(Cross(a,c,b)*Cross(a,b,d)>=0)&&
(Cross(c,a,d)*Cross(c,d,b)>=0);
}
int cmp1(const void *x,const void *y)
{
point *A=(point *)x;
point *B=(point *)y;
return A->y - B->y;
}
int cmp2(const void *x,const void *y)
{
point *A=(point *)x;
point *B=(point *)y;
return A->x - B->x;
}
int n;
point key;
int deal(point num[],int k)
{
point t;
int ans=10000,cnt;
for(int i=1;i