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/32768 K (Java/Others)
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.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
3
inline double CrossProduct(node a, node b, node c){
return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}
//Calculate the crossproduct inline bool SegX(node p1, node p2, node p3, node p4){
double d1 = CrossProduct(p3, p4, p1);
double d2 = CrossProduct(p3, p4, p2);
double d3 = CrossProduct(p1, p2, p3);
double d4 = CrossProduct(p1, p2, p4);
return (d1 * d2 <= && d3 * d4 <= );
}
//Judge whether the line segments intersact
#include <bits/stdc++.h> using namespace std; struct node{
double x, y;
} pa[], pb[]; int n, num; inline double CrossProduct(node a, node b, node c){
return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
} inline bool SegX(node p1, node p2, node p3, node p4){
double d1 = CrossProduct(p3, p4, p1);
double d2 = CrossProduct(p3, p4, p2);
double d3 = CrossProduct(p1, p2, p3);
double d4 = CrossProduct(p1, p2, p4);
return (d1 * d2 <= && d3 * d4 <= );
} int main(){ while (~scanf("%d", &n), n){
num = ;
for (int i = ; i <= n; ++i) scanf("%lf%lf%lf%lf", &pa[i].x, &pa[i].y, &pb[i].x, &pb[i].y);
for (int i = ; i <= n - ; ++i)
for (int j = i + ; j <= n; ++j)
if (SegX(pa[i], pb[i], pa[j], pb[j])) ++num;
printf("%d\n", num);
} return ; }
HDU1086 You can Solve a Geometry Problem too(计算几何)的更多相关文章
- (叉积,线段判交)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 ...
- hdu_1086 You can Solve a Geometry Problem too(计算几何)
http://acm.hdu.edu.cn/showproblem.php?pid=1086 分析:简单计算几何题,相交判断直接用模板即可. 思路:将第k条直线与前面k-1条直线进行相交判断,因为题目 ...
- 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 ...
- 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/ ...
- 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(判断两线段是否相交)
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 ...
随机推荐
- DFS:Tempter of the Bone (规定时间达到规定地点)
解题心得: 1.注意审题,此题是在规定的时间达到规定的地点,不能早到也不能晚到.并不是最简单的dfs 2.在规定时间达到规定的地点有几个剪枝: 一.公式:所需的步骤 - x相差行 - y相差列 = 偶 ...
- [jzoj5233]概率博弈(树形DP)
Description 小A和小B在玩游戏.这个游戏是这样的: 有一棵
- Algorithms(fourth edition)——无向图
1.设计图基本操作API 2.用什么数据结构来表示图并实现API 要求:(1)要预留足够空间 (2)实例方法实现要快 三个选择: 邻接矩阵:布尔矩阵,不满足条件一,而且无法表示平行边 边的数组:不满足 ...
- Android 使用intent传递返回值:startActivityForResult()与onActivityResult()与setResult()参数分析,activity带参数的返回
在一个父Activity通过intent跳转至多个不同子Activity上去,当子模块的代码执行完毕后再次返回父页面,将子activity中得到的数据显示在主界面/完成的数据交给父Activity处理 ...
- Java类和对象 详解(一)---写的很好通俗易懂---https://blog.csdn.net/wei_zhi/article/details/52745268
https://blog.csdn.net/wei_zhi/article/details/52745268
- 最少的硬币数量组合出1到m之间的任意面值(贪心算法)
题目描述: 你有n种不同面值的硬币,每种面值的硬币都有无限多个,为了方便购物,你希望带尽量少的硬币,并且要能组合出 1 到 m 之间(包含1和m)的所有面值. 输入描述: 第一行包含两个整数:m ,n ...
- Leetcode 640.求解方程
求解方程 求解一个给定的方程,将x以字符串"x=#value"的形式返回.该方程仅包含'+',' - '操作,变量 x 和其对应系数. 如果方程没有解,请返回"No so ...
- Leetcode 500.键盘行
键盘行 给定一个单词列表,只返回可以使用在键盘同一行的字母打印出来的单词.键盘如下图所示. 示例: 输入: ["Hello", "Alaska", " ...
- gym101532 2017 JUST Programming Contest 4.0
台州学院ICPC赛前训练5 人生第一次ak,而且ak得还蛮快的,感谢队友带我飞 A 直接用claris的模板啊,他模板确实比较强大,其实就是因为更新的很快 #include<bits/stdc+ ...
- 初学Linux 命令
查看ip:ifconfig 切换用户:us root(root为用户名) 显示当前目录:pwd 列出当前目录下所有文件:ls 进入某个目录 :cd 创建一个文件夹:mkdir 创建多个目录(当没有该父 ...