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) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6997 Accepted Submission(s): 3385
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.
A test case starting with 0 terminates the input and this test case is not to be processed.
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
1
3这是一道几何题。 就是在于你是否会推断两条直线直接是否有交点的方法。剩下就非常easy了。推断AB和CD两线段是否有交点:同一时候满足两个条件:('x'表示叉积)1.C点D点分别在AB的两側.(向量(ABxAC)*(ABxAD)<=0)2.A点和B点分别在CD两側.(向量(CDxCA)*(CDxCB)<=0)</pre><pre name="code" class="cpp">
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath> using namespace std; struct Node
{
double x1, y1, x2, y2;
}point[105];
int n; double work(double x1, double y1, double x2, double y2)
{
return x1 * y2 - x2 * y1;
} bool judge(int i, int j)
{
double a = work(point[i].x1 - point[j].x1, point[i].y1 - point[j].y1, point[j].x2 - point[j].x1, point[j].y2 - point[j].y1);
double c = work(point[j].x2 - point[i].x1, point[j].y2 - point[i].y1, point[i].x2 - point[i].x1, point[i].y2 - point[i].y1);
double b = work(point[i].x2 - point[j].x1, point[i].y2 - point[j].y1, point[j].x2 - point[j].x1, point[j].y2 - point[j].y1);
double d = work(point[j].x1 - point[i].x1, point[j].y1 - point[i].y1, point[i].x2 - point[i].x1, point[i].y2 - point[i].y1);
a = a * b;
c = c * d;
if(a <= 0 && c <= 0)
return true;
return false;
} int main()
{
while(cin >> n, n){
for(int i = 0; i < n; i++)
cin >> point[i].x1 >> point[i].y1 >> point[i].x2 >> point[i].y2;
int count = 0;
for(int i = 0; i < n; i++)
{
for(int j = i + 1; j < n; j++)
if(judge(i, j))
count++;
}
cout << count << endl;
}
return 0;
}
HDU 1086:You can Solve a Geometry Problem too的更多相关文章
- (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
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 (几何)
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 ...
- 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 ...
- (叉积,线段判交)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 ...
- HDUOJ1086You can Solve a Geometry Problem too
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
随机推荐
- Composite Design Pattern 设计模式组合
设计模式组合,它能够更类组合在一类,形成一个树状结构. #include <set> #include <iostream> #include <string> u ...
- Gitblit配置
Gitblit的安装配置及访问-windows (2013-09-11 11:52:31) 转载▼ 分类: android基础 Git 是现在很流行的分布式版本控制工具,github更是人人皆知. ...
- vs2015 安装问题汇总
1. The product version that you are trying to set up is earlier than the version already installed o ...
- Oracle SQL Lesson (10) - 使用DDL语句创建和管理表
数据库对象TableViewSequenceIndexSynonym 对象名称最长30个字符,不能与当前用户下其他对象重名.create table "select" as sel ...
- The example program of C on point
计划一: #include<stdio.h> #define N_VALUES 5 int main( void ) { float values[N_VALUES]; float *vp ...
- web:转盘抽奖
移动web:转盘抽奖(幸运大转盘) 为了获取客户.回馈客户,平台一般会推出抽奖活动类的营销页.因此web页面中,有各式各样的抽奖效果. 格子式(九宫格),背景滚动式(数字/文字/图案),旋转式(转 ...
- CodeForces 10C. Digital Root
乞讨A.B.C ∈[1.N] && A*B != C,d(A*B) == d(C)组的数量. 首先要知道d(x) = (x%9 == 0 ? 9 : x%9); 那么则会有A*B == ...
- Python爬虫(一)
花了四天的时间用python写了个简单的爬虫程序.整个过程分为两个部分:工具的安装和程序的实现 本文并没有讲程序的详细实现遇到的问题,而是对着手前一些前期的准备 第一部分(工具的安装) 开发工具的下载 ...
- 【转】d3d的投影矩阵推导
原帖地址:http://blog.csdn.net/popy007/article/details/4091967 上一篇文章中我们讨论了透视投影变换的原理,分析了OpenGL所使用的透视投影矩阵的生 ...
- Ehcache 整合Spring 使用页面、对象缓存(转)
Ehcache在很多项目中都出现过,用法也比较简单.一般的加些配置就可以了,而且Ehcache可以对页面.对象.数据进行缓存,同时支持集群/分布式缓存.如果整合Spring.Hibernate也非常的 ...