(叉积,线段判交)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)
Total Submission(s): 12959 Accepted Submission(s): 6373
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.
叉积求线段判交的参考链接:
https://www.cnblogs.com/Duahanlang/archive/2013/05/11/3073434.html
https://www.cnblogs.com/tuyang1129/p/9390376.html
C++代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct Point{
double x1,y1,x2,y2;
}node[];
int cross(const Point &a, const Point &b){
double k1 = (a.x2 - a.x1) * (b.y1 - a.y1) - (a.y2 - a.y1) * (b.x1 - a.x1);
double k2 = (a.x2 - a.x1) * (b.y2 - a.y1) - (a.y2 - a.y1) * (b.x2 - a.x1);
if(k1 * k2 <= ){
return ;
}
else
return ;
}
int main(){
int n;
while(scanf("%d",&n),n){
int ans = ;
for(int i = ; i < n; i++){
scanf("%lf%lf%lf%lf",&node[i].x1,&node[i].y1,&node[i].x2,&node[i].y2);
}
for(int i = ; i < n-; i++){
for(int j = i + ; j < n; j++){
ans += (cross(node[i],node[j])) && (cross(node[j],node[i]));
}
}
printf("%d\n",ans);
}
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 M ...
- 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 ...
- (线段判交的一些注意。。。)nyoj 1016-德莱联盟
1016-德莱联盟 内存限制:64MB 时间限制:1000ms 特判: No通过数:9 提交数:9 难度: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 ...
- 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 ...
- 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 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/ ...
- 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 ...
随机推荐
- linode上切换Linux到FreeBSD
PS:不是真正的无缝切换,数据需要自己备份.还原. Linode官方给出了一篇文章:https://www.linode.com/docs/tools-reference/custom-kernels ...
- Ubuntu Firefox HTML5
sudo apt-get install ubuntu-restricted-extras
- How to install Arch Linux
fdisk -l mkfs.ext4 /dev/sdaX mount /dev/sdaX /mnt mkdir -p /mnt/boot/ mount /dev/sdaY /mnt/boot/ arc ...
- JQuery operate xml
msg is <?xml ?> <Parameters> <WorkflowName>...</WorkflowName> </Parameter ...
- 皮皮虾FAQ
我们提供的软件,是市场上比较好操作的,如果有其他的软件也是可以使用我们的ip的 Windows 1.windows找不到粘贴的地方 window打开窗口后,请在屏幕右下角找小飞机,右键即可 2.win ...
- 数据库 -- pymysql
pythen3连接mysql pymsql介绍 PyMySQL 是在 Python3.x 版本中用于连接 MySQL 服务器的一个库,Python2中则使用mysqldb. Django中也可以使用P ...
- Java实现一个双向链表的倒置功能
题目要求:Java实现一个双向链表的倒置功能(1->2->3 变成 3->2->1) 提交:代码.测试用例,希望可以写成一个Java小项目,可以看到单元测试部分 该题目的代码, ...
- Collect devices information
Collect devices information root@vpx-test# kenv > kenv.txt root@vpx-test# sysctl -a > sysctl_a ...
- Qt Creator 搭配Git 版本控制
再次介绍一下Git的使用,这次是在Coding.net上部署项目的.这个是写给大作业合作的小伙伴们(我和我的A奶朋友们和某A的男朋友)看的. 安装Git 首先安装Git(msysGit) 下载地址 h ...
- spring cloud + mybatis 分布式 微服务 b2b2c 多商户商城 全球部署方案
用java实施的电子商务平台太少了,使用spring cloud技术构建的b2b2c电子商务平台更少,大型企业分布式互联网电子商务平台,推出PC+微信+APP+云服务的云商平台系统,其中包括B2B.B ...