| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 7040 | Accepted: 2907 |
Description
An example is shown below:

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<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
#define ms(a,b)memset(a,b,sizeof(a))
#define eps 1e-10
#define inf 1e8
int n,m,cntl,cntp;
int Map[500][500];
double add(double a,double b)
{
if(abs(a+b)<eps*(abs(a)+abs(b))) return 0;
return a+b;
}
struct P
{
double x,y;
P(){}
P(double x,double y): x(x),y(y){}
P operator + (P p)
{
return P(add(x,p.x),add(y,p.y));
}
P operator - (P p)
{
return P(add(x,-p.x),add(y,-p.y));
}
P operator *(double d)
{
return P(x*d,y*d);
}
double dot (P p)
{
return add(x*p.x,y*p.y);
}
double det(P p)
{
return add(x*p.y,-y*p.x);
}
}p[35],q[35],inter[500];
bool on_seg(P p1,P p2,P q)
{
return (p1-q).det(p2-q)==0&&(p1-q).dot(p2-q)<0;
}
bool bianjieon_seg(P p1,P p2,P q)
{
return (p1-q).det(p2-q)==0&&(p1-q).dot(p2-q)<=0;
}
P intersection(P p1,P p2,P q1,P q2)
{
return p1+(p2-p1)*((q2-q1).det(q1-p1)/(q2-q1).det(p2-p1));
}
bool xiangjiao(P p1,P p2,P p3,P p4)
{
if((p1-p2).det(p3-p4)==0)
{
return false;
}
P r=intersection(p1,p2,p3,p4);
if(on_seg(p1,p2,r)&&on_seg(p3,p4,r))
return true;
return false;
}
bool bianjiexiangjiao(P p1,P p2,P p3,P p4)
{
if((p1-p2).det(p3-p4)==0)
{
return false;
}
P r=intersection(p1,p2,p3,p4);
if(bianjieon_seg(p1,p2,r)&&bianjieon_seg(p3,p4,r))
return true;
return false;
}
int main()
{
while(~scanf("%d",&n))
{
int cnt=0;
for(int i=0;i<n;i++)
scanf("%lf%lf%lf%lf",&p[i].x,&p[i].y,&q[i].x,&q[i].y);
p[n].x=0;p[n].y=0;q[n].x=0;q[n].y=100;
p[n+1].x=0;p[n+1].y=100;q[n+1].x=100;q[n+1].y=100;
p[n+2].x=100;p[n+2].y=100;q[n+2].x=100;q[n+2].y=0;
p[n+3].x=100;p[n+3].y=0;q[n+3].x=0;q[n+3].y=0;
double xx,yy;
scanf("%lf%lf",&xx,&yy);
P st=P(xx,yy);
for(int i=0;i<=n+3;i++)
for(int j=i+1;j<=n+3;j++)
{
if(bianjiexiangjiao(p[i],q[i],p[j],q[j]))
{
if(i>=n||j>=n)
inter[cnt++]=intersection(p[i],q[i],p[j],q[j]);
}
}
int ans=999999;
for(int i=0;i<cnt;i++)
{
int tmp=0;
for(int j=0;j<n;j++)
{
if(xiangjiao(st,inter[i],p[j],q[j]))
tmp++;
}
ans=min(tmp,ans);
}
printf("Number of doors = %d\n",ans+1);
}
return 0;
}
825




被折叠的 条评论
为什么被折叠?



