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 ...
随机推荐
- 使用javascript判断浏览器对css3的支持情况【译】
Quick Tip: Detect CSS3 Support in Browsers with JavaScript Jeffrey Way on Nov 15th 2010 步骤 1 首先我们要确 ...
- ubuntu硬件配置查看命令
主板:sudo dmidecode |grep -A16 "System Information$"
- 在Ubuntu Kylin下安装QQ教程
下载: 下载地址:http://www.ubuntukylin.com/application/show.php?lang=cn&id=279 下载后解压得到wine-qqintl文件夹,里面 ...
- POI读取/写入Excel文件
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io ...
- MyBatis的Dao层注入SqlSession
有点坑爹,以前没用过Mybatis,最近才用,而且一直用Mybatis推荐的接口映射的方式,但是今天有人告诉我接口方式用得少,大多还是采用从配置文件里面读sql的方式,当然接口也是类似的,都是利用ma ...
- iOS抓包Charles 操作
今天就来看一下Mac上如何进行抓包,之前有一篇文章介绍了使用Fidder进行抓包 http://blog.csdn.net/jiangwei0910410003/article/details/198 ...
- C++中new和delete来创建和释放动态数组
在C++编程中,使用new创建数组然后用delete来释放. 一.创建并释放一维数组 #include<iostream> using namespace std; int main() ...
- 去掉DataTable中重复的行
//DataView dv = dt3.DefaultView; //dt3默认的虚拟视图 //dv.Sort = "wmid asc"; //排序 ///dv.ToTab ...
- 使用KNN对MNIST数据集进行实验
由于KNN的计算量太大,还没有使用KD-tree进行优化,所以对于60000训练集,10000测试集的数据计算比较慢.这里只是想测试观察一下KNN的效果而已,不调参. K选择之前看过貌似最好不要超过2 ...
- Winsock系列函数 及 Socket通信流程
Socket是一种网络通信机制 Winsock系列函数 1. Socket 创建socket 2. Connect 尝试连接远端Socket 3. Send 在某个Socket 向远端 ...