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/ ...
随机推荐
- php在cli和cgi方式下获取服务器ip的实例
php cli方式下获取服务器ip php内核没有提供这样的命令,需要借助linux中的命令ifconfig来实现,如下两个函数代码: function getServerIp(){ ...
- python运维开发(二十一)----文件上传和验证码+session
内容目录: 文件上传 验证码+session 文件和图片的上传功能 HTML Form表单提交,实例展示 views 代码 HTML ajax提交 原生ajax提交,XMLHttpRequest方式上 ...
- js加载优化三
Javascript性能优化之异步加载和执行 Author:小欧2013-09-17 随着科技的发展,如今的网站和五六年前相比,现在的人们对web的要求越来越高了,用户体验,交互效果,视觉效果等等都有 ...
- Win 10 、Win 8 系统默认字体如何修改为宋体
Win 10 字体改为宋体方法:新建一个文本文档txt,将如下代码复制进去:Windows Registry Editor Version 5.00[HKEY_LOCAL_MACHINE\SOFTWA ...
- SVD学习
前言: 上一次写了关于PCA与LDA的文章,PCA的实现一般有两种,一种是用特征值分解去实现的,一种是用奇异值分解去实现的.在上篇文章中便是基于特征值分解的一种解释.特征值和奇异值在大部分人的印象中, ...
- Linux系统编程(22)——响应信号
进程对信号的响应 进程可以通过三种方式来响应一个信号: 1.忽略信号,即对信号不做任何处理,其中,有两个信号不能忽略:SIGKILL及SIGSTOP: 2.捕捉信号.定义信号处理函数,当信号发生时,执 ...
- Unix/Linux环境C编程入门教程(36) 初识shell
1.什么是Shell Shell是位为一组,依次代表文件拥有者.同组用户和其他用户的存取权限.通常文件共有3个权限,"r"表示只读:"w"表示可写:&qu ...
- Merge Two Sorted Lists 解答
Question Merge two sorted linked lists and return it as a new list. The new list should be made by s ...
- 为什么和其他语言相比C语言是快速的语言
初入门的我们经常听见别人说"真正的程序员用C语言编程,C是最快的语言因为它是最靠近及其底层的语言."那么和其他语言相比C语言到底有什么特别的呢? C语言没有什么特别,这就是它快速的 ...
- PKU 3667 Hotel(线段树)
Hotel The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a ...