poj 1066 线段相交
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 5431 | Accepted: 2246 |
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
Source
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <math.h> #define MAXX 35
#define eps 1e-6
using namespace std; typedef struct point
{
double x,y;
} point;
typedef struct line
{
point st,ed;
} line; bool dy(double x,double y)
{
return x>y+eps;
}
bool xy(double x,double y)
{
return x<y-eps;
}
bool xyd(double x,double y)
{
return x<y+eps;
}
bool dyd(double x,double y)
{
return x>y-eps;
}
bool dd(double x,double y)
{
return fabs(x-y)<eps;
} double crossProduct(point a,point b,point c)
{
return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
} bool onSegment(point a,point b,point c)
{
double maxx=max(a.x,b.x);
double maxy=max(a.y,b.y);
double minx=min(a.x,b.x);
double miny=min(a.y,b.y);
if(dd(crossProduct(a,b,c),0.0)&&xyd(c.x,maxx)&&dyd(c.x,minx)
&&xyd(c.y,maxy)&&dyd(c.y,miny))
return true;
return false;
} bool segIntersect(point p1,point p2,point p3,point p4)
{
double d1=crossProduct(p3,p4,p1);
double d2=crossProduct(p3,p4,p2);
double d3=crossProduct(p1,p2,p3);
double d4=crossProduct(p1,p2,p4);
if(xy(d1*d2,0.0)&&xy(d3*d4,0.0))
return true;
/*if(dd(d1,0.0)&&onSegment(p3,p4,p1))
return true;
if(dd(d2,0.0)&&onSegment(p3,p4,p2))
return true;
if(dd(d3,0.0)&&onSegment(p1,p2,p3))
return true;
if(dd(d4,0.0)&&onSegment(p1,p2,p4))
return true;
*/
return false;
} point p[10010];
line li[MAXX];
int num[MAXX]; int main()
{
int n,m,i,j;
point tar;
while(scanf("%d",&n)!=EOF)
{
for(i=0; i<n; i++)
{
scanf("%lf%lf%lf%lf",&li[i].st.x,&li[i].st.y,&li[i].ed.x,&li[i].ed.y);
}
scanf("%lf%lf",&tar.x,&tar.y);
i=0;
int cas=0;
for(j=1; j<100; j++)
{
p[cas].x=0;
p[cas++].y=j;
}
for(j=1; j<100; j++)
{
p[cas].x=100;
p[cas++].y=j;
}
for(i=1; i<100; i++)
{
p[cas].x=i;
p[cas++].y=0;
}
for(i=1; i<100; i++)
{
p[cas].x=i;
p[cas++].y=100;
}
int sum;
int minn=0x7fffffff;//printf("%d**\n",cas);
for(i=0; i<cas; i++)
{
sum=0;
for(j=0; j<n; j++)
{
if(segIntersect(tar,p[i],li[j].st,li[j].ed))
{
sum++;
}
}
if(minn>sum)
{
minn=sum;
}//printf("%d**\n",sum);
}
if(n == 0) printf("Number of doors = 1\n");
else
printf("Number of doors = %d\n",minn+1);
} return 0;
}
poj 1066 线段相交的更多相关文章
- poj 1269 线段相交/平行
模板题 注意原题中说的线段其实要当成没有端点的直线.被坑了= = #include <cmath> #include <cstdio> #include <iostrea ...
- poj 2653 线段相交
题意:一堆线段依次放在桌子上,上面的线段会压住下面的线段,求找出没被压住的线段. sol:从下向上找,如果发现上面的线段与下面的相交,说明被压住了.break掉 其实这是个n^2的算法,但是题目已经说 ...
- poj 2653 线段相交裸题(解题报告)
#include<stdio.h> #include<math.h> const double eps=1e-8; int n; int cmp(double x) { if( ...
- poj 1410 线段相交判断
http://poj.org/problem?id=1410 Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- Pipe - POJ 1039(线段相交交点)
题目大意:有一个不反光并且不透光的管道,现在有一束光线从最左端进入,问能达到的最右端是多少,输出x坐标. 分析:刚开始做是直接枚举两个点然后和管道进行相交查询,不过这样做需要考虑的太多,细节不容易 ...
- Pick-up sticks - POJ 2653 (线段相交)
题目大意:有一个木棒,按照顺序摆放,求出去上面没有被别的木棍压着的木棍..... 分析:可以维护一个队列,如果木棍没有被压着就入队列,如果判断被压着,就让那个压着的出队列,最后把这个木棍放进队列, ...
- The Doors - POJ 1556 (线段相交)
题目大意:有一个房间(左上角(0,10),右下角(10,0)),然后房间里有N面墙,每面墙上都有两个门,求出来从初始点(0,5),到达终点(10,5)的最短距离. 分析:很明显根据两点之间直线最短 ...
- POJ 2074 | 线段相交
#include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #defi ...
- 线段相交 poj 1066
// 线段相交 poj 1066 // 思路:直接枚举每个端点和终点连成线段,判断和剩下的线段相交个数 // #include <bits/stdc++.h> #include <i ...
随机推荐
- android 项目学习随笔十一(ListView下拉刷新提示)
1. 设置mHeaderView.setPadding TOPPADING为负值,隐藏刷新提示头布局 在onTouchEvent事件中进行头布局显示隐藏切换 import java.text.Simp ...
- 怎样使用AutoLayOut为UIScrollView添加约束
1.在ViewController中拖入1个UIScrollView,并为其添加约束 约束为上下左右四边与superview对齐 2.在scrollview中,拖入1个UIView,为了便于区分将其设 ...
- oracle sql语言模糊查询--通配符like的使用教程
转自:http://www.cnblogs.com/tyler2000/archive/2011/04/28/oracleSql.html oracle在Where子句中,可以对datetime.ch ...
- ch2-1:创建模块,并调用模块中的函数
模块就是一个包含python代码的文本文件,文件名以.py结尾,这是python扩展名: 1.创建一个模块nester.py,文件内容为: '''这是一个模块,可以打印列表,其中可能包含嵌套列表''' ...
- composer未升级报错
错误: Cannot adopt OID in SQUID-MIB: cacheClients ::= { cacheProtoAggregateStats 15 } Cannot adopt OID ...
- Java遍历Map的3种方式
package test; import java.util.Collection; import java.util.HashMap; import java.util.Map; import ja ...
- WMsg参数常量值
//WMsg参数常量值: //创建一个窗口 const int WM_CREATE = 0x01; //当一个窗口被破坏时发送 const int WM_DESTROY = 0x02; //移动一个窗 ...
- URL List
wifi driver http://wenku.baidu.com/view/5fb275e9b8f67c1cfad6b85e.html http://wenku.baidu.com/view/a5 ...
- 【转】SVN提示:由于目标机器积极拒绝,无法连接 的解决方法
转载地址:http://wxiaolei.blog.163.com/blog/static/1038760120133108180596/ 安装完TSVN之后,checkout时报错,并且后来在cmd ...
- java环境log4j日志环境的配置。
首先需要4个jar包.下载地址如下 http://pan.baidu.com/s/1i4k3fiH 期中包含如下包,放到工程的lib中即可. 除此之外还需要一个配置文件,分享链接如下. htt ...