HDUOJ1086You can Solve a Geometry Problem too
You can Solve a Geometry Problem too
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6340 Accepted Submission(s): 3064
Give you N (1<=N<=100) segments(线段), please output the number of all intersections(交点). You should count repeatedly if M (M>2) segments intersect at the same point.
Note:
You can assume that two segments would not intersect at more than one point.
A test case starting with 0 terminates the input and this test case is not to be processed.
#include<stdio.h>
#include<math.h>
const double eps=1e- ;
typedef struct
{
double x,y;
}point; double min(double a, double b)
{
return a<b?a:b;
}
double max(double a,double b)
{
return a>b?a:b;
}
//判断线段是否有焦点
bool inter(point a ,point b, point c ,point d)
{
if(min(a.x,b.x)>max(c.x,d.x)||min(a.y,b.y)>max(c.y,d.y)||
min(c.x,d.x)>max(a.x,b.x)||min(c.y,d.y)>max(a.y,b.y))
return ;
double h,i,j,k;
h=(b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
i=(b.x-a.x)*(d.y-a.y)-(b.y-a.y)*(d.x-a.x);
j=(d.x-c.x)*(a.y-c.y)-(d.y-c.y)*(a.x-c.x);
k=(d.x-c.x)*(b.y-c.y)-(d.y-c.y)*(b.x-c.x);
return h*i<=eps&&j*k<=eps;
};
point st[],en[];
int main()
{
int n,j,i,cnt=;
while(scanf("%d",&n),n)
{
cnt=;
for( i= ; i<n ; i++ )
scanf("%lf%lf%lf%lf",&st[i].x,&st[i].y,&en[i].x,&en[i].y); for( i= ; i<n ; i++ )
{
for(j=i+ ; j<n ;j++ )
{
if(inter(st[i],en[i],st[j],en[j]))
cnt++;
}
}
printf("%d\n",cnt);
}
return ;
}
HDUOJ1086You can Solve a Geometry Problem too的更多相关文章
- HDU1086You can Solve a Geometry Problem too(判断线段相交)
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
- hdu 1086 You can Solve a Geometry Problem too
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
- (hdu step 7.1.2)You can Solve a Geometry Problem too(乞讨n条线段,相交两者之间的段数)
称号: You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/ ...
- HDU 1086:You can Solve a Geometry Problem too
pid=1086">You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Mem ...
- You can Solve a Geometry Problem too(判断两线段是否相交)
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
- You can Solve a Geometry Problem too(线段求交)
http://acm.hdu.edu.cn/showproblem.php?pid=1086 You can Solve a Geometry Problem too Time Limit: 2000 ...
- (叉积,线段判交)HDU1086 You can Solve a Geometry Problem too
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
- You can Solve a Geometry Problem too (hdu1086)几何,判断两线段相交
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3276 ...
- hdu 1086:You can Solve a Geometry Problem too(计算几何,判断两线段相交,水题)
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
随机推荐
- selectHelper
转:适有修改并调试OK var Sys = (function (ua) { var s = {}; s.IE = ua.match(/msie ([\d.]+)/) ? true : false; ...
- [Android Pro] Swift 3.0多线程
本文只介绍Grand Central Dispath(GCD) 中央调度 个人认为一个GCD就够用了,可能是改版或是其他的在找之前写的多线程方法时发现不能用了,看文档之后发现改了,现在看上去更加简单易 ...
- 特殊汉字“𣸭”引发的对于字符集的思考;mysql字符集;sqlalchemy字符集设置;客户端字符集设置;
字符集.字符序的概念与联系 在数据的存储上,MySQL提供了不同的字符集支持.而在数据的对比操作上,则提供了不同的字符序支持. MySQL提供了不同级别的设置,包括server级.database级. ...
- 硬件负载均衡F5和软负责均衡Nginx
请直接搜索相关文章了解:http://www.ideadata.com.cn/wisdomAction/readWisdom.do?id=75 F5,硬件 优点:能够直接通过智能交换机实现,处理能 ...
- [转]Unicode和UTF-8的关系
Unicode和UTF-8的关系作者: 张军 原文地址: http://blog.renren.com/blog/284133452/485453790 今天中午,我突然想搞清楚Unicode和UTF ...
- java.lang.ClassNotFoundException: Didn't find class "stu.love.neihan.MainActivity" on path: DexPathL
java.lang.ClassNotFoundException: Didn't find class "stu.love.neihan.MainActivity" on path ...
- 企业版Oracle10g的安装-过程
ylbtech-Oracle:企业版Oracle10g的安装-过程 Oracle10g的安装 在Windows操作系统上安装Oracle10g数据库的步骤如下: 0.1)从Oracle的官方网站上下载 ...
- BULLET物理DEMO最新版本
鼠标右键按下并拖动 旋转视角WSAD 前后左右RF 上下QE ...
- crtmpserver实现防盗流和流推送验证 之二
IV. Catching the thieves 抓住小偷 Well, we have just added a secure mechanism to our little streaming se ...
- Binary Tree Postorder Traversal leetcode java
题目: Given a binary tree, return the postorder traversal of its nodes' values. For example: Given bin ...