you can Solve a Geometry Problem too(hdoj1086)
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.
contains multiple test cases. Each test case contains a integer N
(1=N<=100) in a line first, and then N lines follow. Each line
describes one segment with four float values x1, y1, x2, y2 which are
coordinates of the segment’s ending.
A test case starting with 0 terminates the input and this test case is not to be processed.
/*判断AB和CD两线段是否有交点:
同时满足两个条件:('x'表示叉积)
1.C点D点分别在AB的两侧.(向量(ABxAC)*(ABxAD)<=0)
2.A点和B点分别在CD两侧.(向量(CDxCA)*(CDxCB)<=0)*/
/*数据稍微多点我就写错了,不求快但求稳*/
#include<stdio.h>
#include<string.h>
int fun(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4)
{
double d1=(x2-x1)*(y4-y1)-(y2-y1)*(x4-x1),d2=(x2-x1)*(y3-y1)-(y2-y1)*(x3-x1);
if(d2*d1<=)
{
double d3=(x4-x3)*(y1-y3)-(y4-y3)*(x1-x3),d4=(x4-x3)*(y2-y3)-(x2-x3)*(y4-y3);
if(d3*d4<=)
return ;
return ;
}
else
return ;
} int main()
{
double a[][];
int n,i,j;
while(~scanf("%d",&n)&&n)
{
memset(a,,sizeof(a));
int count=;
for(i=;i<=n;i++)
scanf("%lf%lf%lf%lf",&a[i][],&a[i][],&a[i][],&a[i][]);
for(j=;j<=n;j++)
for(i=j+;i<=n;i++)
count+=fun(a[j][],a[j][],a[j][],a[j][],a[i][],a[i][],a[i][],a[i][]);
printf("%d\n",count);
}
}
you can Solve a Geometry Problem too(hdoj1086)的更多相关文章
- 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 ...
- 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 ...
- 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 1086 You can Solve a Geometry Problem too( 判断线段是否相交 水题 )
链接:传送门 题意:给出 n 个线段找到交点个数 思路:数据量小,直接暴力判断所有线段是否相交 /*************************************************** ...
- (叉积,线段判交)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 ...
- 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/ ...
随机推荐
- bootstrap模态框垂直居中
很久没有写东西了,之前想写一些移动端的东西以后补上吧,移动端发展还是蛮快的,回正题. 因为最近在弄一个系统,系统中引用了bootstrap,发现模态框垂直不居中,遂搜索了一下,也都试了一下,无非都是在 ...
- python运维开发(十九)----Django后台表单验证、session、cookie、model操作
内容目录: Django后台表单验证 CSRF加密传输 session.cookie model数据库操作 Django后台Form表单验证 Django中Form一般有2种功能: 1.用于做用户提交 ...
- PermissionError: [WinError 32] 另一个程序正在使用此文件,进程无法访问。: 'C:\\Users\\video\\AppData\\Local\\Temp\\tmpfipzk8ma'--问题解决
学习python+selenium总是遇到各种问题 代码如下: from selenium import webdriverbrowser = webdriver.PhantomJS() #浏览器初始 ...
- Win7网络检测 WindowsAPICodePack
原文:http://www.cnblogs.com/yincheng01/archive/2010/05/30/2213234.html 在Windows7操作系统下,支持的网络类型越来越复杂,微软提 ...
- 转:C# 中的委托和事件
引言 委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真是太容易了,而没有过去 ...
- Jquery之家5个顶级Material Design框架
谷歌Material Design在如今的前端页面设计中非常流行.Material Design的设计风格向我们展示了一个简单而有内涵的现代UI设计方案. Material Design是如此的简洁美 ...
- UGUI Button控件
今天一起来学习下Button控件, Button控件其实是由Text,Button,Image组件形成的. 这里就简单介绍下Button组件 Interactable: 代表该组件是否进行交互, 我们 ...
- Kyoya and Colored Balls(组合数)
Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 使用JUnit单元测试入门
一.JUnit是什么? JUnit是一个开发源代码的java测试框架,用于编写和运行可重复的测试.它是用于单元测试框架体系xUnit的一个实例(用于java语言).JUnit最初是由Erich Gam ...
- HDU2037 贪心 动归均可+证明
今年暑假不AC Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...