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. MySQL-(Master-Slave)配置

    1.两台机器,安装好版本一致的MySQL 192.168.29.128 (master) MySQL-5.6.21 192.168.29.129 (slave) MySQL-5.6.21 2.配置ma ...

  2. Vs打包工程 错误: Unable to update the dependencies of the project (转)

    Setup Project 错误: Unable to update the dependencies of the project 在VS2010中编译包含安装工程的解决方案提示错误:Unable ...

  3. 10. windows与linux文件共享

    1. 关闭防火墙 /etc/init.d/iptables stop 2. C:\Users\cfm>ping 192.168.232.131 正在 Ping 192.168.232.131 具 ...

  4. 解决EditorLineEnds.ttr被锁定导致Delphi2006-2010无法启动的问题

    在批处理最后增加了启动Delphi的命令.将批处理和Delphi放在同一目录即可. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...

  5. 浅谈OpenGL变换矩阵

    OpenGL中使用的矩阵全为列向量为主的矩阵. 参考OpenGL变换网站为  http://www.songho.ca/opengl/gl_transform.html 1.什么是GL_MODELVI ...

  6. php中好用的时间函数

    //查询数据30天的数据$y=date("Y",time());$m=date("m",time());$d=date("d",time() ...

  7. 8天掌握EF的Code First开发系列之2 简单的CRUD操作

    本文出自8天掌握EF的Code First开发系列,经过自己的实践整理出来. 本篇目录 创建控制台项目 根据.Net中的类来创建数据库 简单的CRUD操作 数据库模式更改介绍 本章小结 本人的实验环境 ...

  8. php 乱码解决

    1)首先确定你的终端编码,如果你不知道如何确定,分别执行这两段代码,看看哪个能输出中文. PHP code   ? 1 echo pack("H12","E4B8ADE6 ...

  9. 【MVC】 基础

    [MVC] 基础 一. Controller ActionResult ContentResult  返回string类型 EmptyResult     空 FileContentResult    ...

  10. IE调试网页之四:F12 开发人员工具控制台错误消息 (Windows)(转载)

    F12 工具控制台可以报告在运行时期间发生的错误和信息消息.本文将介绍错误消息,并提供有关如何修正这些错误的建议. 简介 F12 工具控制台错误消息提供了一些代码(例如,SEC7111 或 HTML1 ...