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 ...
随机推荐
- ZOJ--3631--Watashi's BG【枚举】
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4777 题意:有n天,告诉你每天的花费,别人给你一笔资金m,你自己也有一部 ...
- UVa 11408 - Count DePrimes
题目:一个数的素因子的和假设也是素数就叫做DePrimes,统计给定区间内的DePrimes. 分析:数论.本题使用用一种素数的筛法,欧拉筛法,也加线性筛法. 这样的方法,每次删选分两种情况:1.素因 ...
- log4j 实例 , 浅析
一.新建log4j.propperties,放在工程的src目录下. #fileAppender log4j.rootCategory = DEBUG,file,consoleAppender log ...
- Lua语言在Wireshark中使用(转)
1. 检查Wireshark的版本是否支持Lua 打开Wireshark,点击“HelpàAbout Wireshark”菜单,查看弹出的对话框,如果有“with Lua 5.1”表示支持 ...
- android Animation动画的xml使用
在Android应用程序,使用动画效果,能带给用户更好的感觉,做动画能够通过XML或Android代码来实现. Animation动画效果的实现能够通过两种方式进行实现,一种是tweened anim ...
- 网页信息抓取进阶 支持Js生成数据 Jsoup的不足之处
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/23866427 今天又遇到一个网页数据抓取的任务,给大家分享下. 说道网页信息抓取 ...
- RH033读书笔记(3)-Lab 4 Browsing the Filesystem
Lab 4 Browsing the Filesystem Sequence 1: Directory and File Organization 1. Log in as user student ...
- 使用Emacs muse制作幻灯片
PPT太受欢迎.总是必要的交流会议.我看到一个很酷javascript实现,取代PPT. 不过还是很喜欢Emacs要做的事,即使文件难听点. 现在,用muse slidy, 一大区别. 简单的说mus ...
- oracle物化视图使用+hibernate
使用过程 ----删除 TRUNCATE TABLE mlog$_xxx_lxz_tmp;DROP MATERIALIZED VIEW LOG ON xxx_lxz_tmp; drop materia ...
- ListView装上拉电阻下拉刷新
主要用到了这个几个文件.MainActivity是界面的Activity,MyAdapter是ListView的自己定义适配,MyListView是自己定义带头部LIistView,假设仅仅须要上拉载 ...