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 ...
随机推荐
- Windows Phone开发(9):关于页面状态
原文:Windows Phone开发(9):关于页面状态 按照一般做法,刚学会如何导航,还是不够的,因为要知道,手机里面的每个页面,就如同Web页面一样,是无状态的. 啥是无状态?如果我们玩过Web开 ...
- crm2011js子网格导航栏字段事件操作
- Java EE (2) -- Java EE 6 Enterprise JavaBeans Developer Certified Expert(1z0-895)
Introduction to Java EE Gain an understanding of the Java Platform, Enterprise Edition (Java EE) Exa ...
- Python使用subprocess的Popen要调用系统命令
当我们须要调用系统的命令的时候,最先考虑的os模块.用os.system()和os.popen()来进行操作.可是这两个命令过于简单.不能完毕一些复杂的操作,如给执行的命令提供输入或者读取命令的输出, ...
- 使用CMakeLists.txt 判断编译器是否支持C++11
#将下面的内容添加到CMakeLists.txt当中include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++11&quo ...
- C. Captain Marmot (Codeforces Round #271)
C. Captain Marmot time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Autofac 入门
Autofac 入门文档 原文链接:http://docs.autofac.org/en/latest/getting-started/index.html 在程序中使用Autofac的基本模式是: ...
- HDU--3081--Marriage Match II--最大匹配,匈牙利算法
Marriage Match II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- js字的数目的计算方法(与word计算公式为)
[背景] 用户往往需要一定数量的单词填写必填字段限制,但js由value.length取出来的往往差异很大,与实际的话.通常真正的用户抱怨.很显然,我没有写那么多字,但系统提示超过字数限制.然后,我学 ...
- perl操作sqlserver实现BCP
#!C:\Perl64\bin #由BCP备份和恢复SQLSERVER指定表 use 5.014; #加载用户和password型材 my $username ; my $passwd; ##得到us ...