You can Solve a Geometry Problem too

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10204    Accepted Submission(s): 5042

Problem Description
Many
geometry(几何)problems were designed in the ACM/ICPC. And now, I also
prepare a geometry problem for this final exam. According to the
experience of many ACMers, geometry problems are always much trouble,
but this problem is very easy, after all we are now attending an exam,
not a contest :)
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.

 
Input
Input
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.
 
Output
For each case, print the number of intersections, and one line one case.
 
Sample Input
2
0.00 0.00 1.00 1.00
0.00 1.00 1.00 0.00
3
1.00 0.00 1.00 1.00
0.00 1.00 1.00 0.000
0.00 0.00 1.00 0.00
0
 
Sample Output
1
3
 
Author
lcy
判断两个线段有没有交点  百度  叉积
/*
判断AB和CD两线段是否有交点:
同时满足两个条件:('x'表示叉积)
1.C点D点分别在AB的两侧.(向量(ABxAC)*(ABxAD)<=0)
2.A点和B点分别在CD两侧.(向量(CDxCA)*(CDxCB)<=0)
*/
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
struct node{
double x,y;
}a[],b[];
double chaji(node a,node b,node c){
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
int judge(node a,node b,node c,node d){
if(max(a.x,b.x)<min(c.x,d.x)||max(c.x,d.x)<min(a.x,b.x))
return ;
if(max(a.y,b.y)<min(c.y,d.y)||min(a.y,b.y)>max(c.y,d.y))
return ;
if(chaji(a,c,d)*chaji(b,c,d)<=&&(chaji(c,a,b)*chaji(d,a,b)<=))
return ;
//if(chaji(c,d,a,b)<=0||chaji(c,d,b,a)<=0)
// return 1;
//if(chaji(d,c,a,b)<=0||chaji(d,c,b,a)<=0)
// return 1;
return ;
}
int main(){
int t;
int i,j;
while(scanf("%d",&t)!=EOF){
if(t==)
break;
for(i=;i<=t;i++){
scanf("%lf%lf%lf%lf",&a[i].x,&a[i].y,&b[i].x,&b[i].y);
}
int ans=;
for(i=;i<=t;i++){
for(j=i+;j<=t;j++){
if(judge(a[i],b[i],a[j],b[j]))
{
ans++;
//cout<<judge(a[i],b[i],a[j],b[j])<<endl;
}
}
}
printf("%d\n",ans);
} }

hdu 1086 You can Solve a Geometry Problem too的更多相关文章

  1. 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 ...

  2. 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 ...

  3. hdu 1086 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/3 ...

  4. hdu 1086 You can Solve a Geometry Problem too [线段相交]

    题目:给出一些线段,判断有几个交点. 问题:如何判断两条线段是否相交? 向量叉乘(行列式计算):向量a(x1,y1),向量b(x2,y2): 首先我们要明白一个定理:向量a×向量b(×为向量叉乘),若 ...

  5. HDU 1086 You can Solve a Geometry Problem too( 判断线段是否相交 水题 )

    链接:传送门 题意:给出 n 个线段找到交点个数 思路:数据量小,直接暴力判断所有线段是否相交 /*************************************************** ...

  6. Hdoj 1086.You can Solve a Geometry Problem too 题解

    Problem Description Many geometry(几何)problems were designed in the ACM/ICPC. And now, I also prepare ...

  7. 【HDOJ】1086 You can Solve a Geometry Problem too

    数学题,证明AB和CD.只需证明C.D在AB直线两侧,并且A.B在CD直线两侧.公式为:(ABxAC)*(ABxAD)<= 0 and(CDxCA)*(CDxCB)<= 0 #includ ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. silverlight简单数据绑定3

    3种数据绑定模式  OneTime(一次绑定) OneWay(单项绑定) TwoWay(双向绑定) OneTime:仅在数据绑定创建时使用数据源更新目标. 列子: 第一步,创建数据源对象让Person ...

  2. ssh配置文件说明

    配置“/etc/ssh/ssh_config”文件 “/etc/ssh/ssh_config” 文件是OpenSSH系统范围的配置文件,允许你通过设置不同的选项来改变客户端程序的运行方式.这个文件的每 ...

  3. MessageFormat不支持{

    转自 :http://zqc-0101.iteye.com/blog/1140140 MessageFormat用来格式化一个消息,通常是一个字符串,比如: String str = "I' ...

  4. Python图像处理库:Pillow 初级教程

    Python图像处理库:Pillow 初级教程 2014-09-14 翻译 http://pillow.readthedocs.org/en/latest/handbook/tutorial.html ...

  5. Flume 远程写HDFS

    现在的需求是在一台Flume采集机器上,往Hadoop集群上写HDFS,该机器没有安装Hadoop. 这里的Flume版本是1.6.0,Hadoop版本是2.7.1. 把Hadoop集群的hdfs-s ...

  6. css3颜色

    镂空字的2种做法

  7. 基于percona 5.7的xtrabackup实践

    环境:         centerOS7         percona 5.7         xtrabackup  2.4(5.7只支持2.4已上的版本)   第一步:  安装xtraback ...

  8. Hibernate框架概念

    1.Hibernate是ORM框架,完成对象的持久化操作. 2.允许开发者采用面向对象的方式来操作数据库. 3.安装Hibernate的插件到Eclipse中来自动生成配置文件. 4.Hibernat ...

  9. php乱码解决

    代码示例: <?phpheader("Content-type: text/hml; charset=utf-8");echo "holl 欢迎光临小站,现在正在建 ...

  10. device tree 生成device node 到 platform_device

    http://blog.csdn.net/lichengtongxiazai/article/details/38942033 http://blog.csdn.net/mcgrady_tracy/a ...