计算几何-hdoj-1086

You can Solve a Geometry Problem too

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 7027    Accepted Submission(s): 3397

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

大意:给出若干线段,计算交点个数。多条线段交于一点,需要重复计算。端点相交也算线段相交。

计算几何-hdoj-1086

时间: 2024-11-08 18:43:12

计算几何-hdoj-1086的相关文章

hdoj 1086 You can Solve a Geometry Problem too 【计算几何】

题意:就是判断各线段之间有没有交点. 判断两线段相交,要运用到叉积.两个线段相交肯定相互跨越,假设一个条线段(p1p2),另一条是(q1q2),那么p1p2肯定在q1q2线段的两侧,那么运用叉积如果p1p2跨越q1q2的话(q1p1)x(q2p2)<= 0.同样也要验证 q1q2是不是也跨越p1p2,注意:p1p2跨越q1q2,不代两个线段相交,可能是p1p2跨越直线q1q2,所以说还是要再次判断q1q2是不是跨越p1p2 还有另外一种比较容易理解的解法: 就是如果两个线段相交,那么两线段两端端

计算几何 HDOJ 4720 Naive and Silly Muggles

题目传送门 /* 题意:给三个点求它们的外接圆,判断一个点是否在园内 计算几何:我用重心当圆心竟然AC了,数据真水:) 正解以后补充,http://www.cnblogs.com/kuangbin/archive/2013/09/11/3315055.html */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <string

HDOJ 1086 You can Solve a Geometry Problem too

打算好好练练计算几何. 昨天经过反省决定戒掉一做题就看题解的恶习,结果今天做题就抓瞎了... 因为刚开始有很多公式方法不知道,所以完全自己做就毫无思路= =.还是忍住没看题解,打开了手边的CLRS,我本来以为这里面关于计算几何的篇幅很少,应该讲不了什么. 然后我发现我错了,经典就是经典.关于判断线段相交的方法,讲的非常清楚,每一步包括叉乘等细节都有很详细的讲解. 看完之后手动敲,1A,代码: #include <stdio.h> #include <math.h> #include

HDOJ 1086 模板水过

You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8693    Accepted Submission(s): 4232 Problem Description Many geometry(几何)problems were designed in the ACM/I

hdu 1086(计算几何入门题——计算线段交点个数)

链接:http://acm.hdu.edu.cn/showproblem.php?pid=1086 You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7167    Accepted Submission(s): 3480 Problem Description Ma

HDU 1086 [You can Solve a Geometry Problem too] 计算几何

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1086 题目大意:给N条线段,问这些线段共有多少交点,多线交于一点要重复计算. 关键思想:叉乘可根据右手法则判断正负,相互跨越或者一条线段端点在另一条线段上则交点数+1. 代码如下: #include <iostream> using namespace std; const int MAXN=110; struct point{ double x,y; }; struct line{ point

hdoj 2036 (计算几何,叉积求面积)

改革春风吹满地 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 24179    Accepted Submission(s): 12504 Problem Description “ 改革春风吹满地,不会AC没关系;实在不行回老家,还有一亩三分地.谢谢!(乐队奏乐)” 话说部分学生心态极好,每天就知道游戏,这次考试如此简单的题目,也是云

hdoj Pipe&amp;&amp;南阳oj管道问题&amp;&amp;poj1039(计算几何问题...枚举)

Pipe Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 240    Accepted Submission(s): 99 Problem Description The GX Light Pipeline Company started to prepare bent pipes for the new transgalactic l

HDOJ 5839 计算几何+暴力

链接: http://acm.hdu.edu.cn/showproblem.php?pid=5839 题意: 给你立体空间内的n个点,问能组成多少个四面体满足 1.至少四条棱相等 2.如果刚好四条棱相等,那么不相等的两条棱不能相邻 题解: 直接暴力,先枚举3个点,如果这三个点组成的三角形三边都不相等,那么就不用枚举第四个点了,其实很多情况都不用枚举第四个点 如果这个三角形是等边或等腰三角形,再分别枚举第四个点,分情况计算 开始的时候忘了判断还要判断四点共面,所以没用Point结构体,结果连样例都

HDOJ 4454 Stealing a Cake 计算几何

暴力枚举角度..... Stealing a Cake Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2495    Accepted Submission(s): 681 Problem Description There is a big round cake on the ground. A small ant plans to