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/32768 K (Java/Others)
Total Submission(s): 10204 Accepted Submission(s): 5042
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.
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.
0
3
判断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的更多相关文章
- 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 (几何)
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条直线交点的个数
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 [线段相交]
题目:给出一些线段,判断有几个交点. 问题:如何判断两条线段是否相交? 向量叉乘(行列式计算):向量a(x1,y1),向量b(x2,y2): 首先我们要明白一个定理:向量a×向量b(×为向量叉乘),若 ...
- HDU 1086 You can Solve a Geometry Problem too( 判断线段是否相交 水题 )
链接:传送门 题意:给出 n 个线段找到交点个数 思路:数据量小,直接暴力判断所有线段是否相交 /*************************************************** ...
- 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 ...
- 【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 ...
- 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(线段求交)
http://acm.hdu.edu.cn/showproblem.php?pid=1086 You can Solve a Geometry Problem too Time Limit: 2000 ...
随机推荐
- 《Linux内核分析》课程总结
朱宇轲 + 原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 不知不觉,在网易 ...
- 相机标定:关于用Levenberg-Marquardt算法在相机标定中应用
LM算法在相机标定的应用共有三处. (1)单目标定或双目标定中,在内参固定的情况下,计算最佳外参.OpenCV中对应的函数为findExtrinsicCameraParams2. (2)单目标定中,在 ...
- 13. Reorder List
Reorder List Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… Y ...
- IIS7 rename application or site
rename site 比较容易,在IIS里面就可以直接 rename,也可以用 cmd 的方式 1. 打开 cmd 2. cd C:\Windows\System32\inetsrv 3. appc ...
- window.parent
今天出现了一个严重的bug,页面在载入时居然导致了页面崩溃,找了近5个小时的代码,才找到了原因(擦,我只能说我水平有限,浪费了太长时间了~). 源代码: var curr = window; whil ...
- libssh2 的集成与应用
http://blog.csdn.net/wyc6668205/article/details/9179197 Xmanager Enterprise 4 putty 等工具都功能都是利用libssh ...
- centos 6 initctl
在centos6中有initctl 可以启动tty等.此命令在 upstart-0.6.5-10.el6.x86_64 rpm包中 或者 mingetty 命令启动 tty #initctl star ...
- 日志分析工具ELK配置详解
日志分析工具ELK配置详解 一.ELK介绍 1.1 elasticsearch 1.1.1 elasticsearch介绍 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分 ...
- 深入学习微框架:Spring Boot(转)
转:http://www.infoq.com/cn/articles/microframeworks1-spring-boot/ 相关参考: https://spring.io/guides/gs/s ...
- C#占位符和格式化字符串
static void Main() { string c=Console.ReadLine(); string d=Console.ReadLine(); Console.WriteLine(c+& ...