HDU 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): 11918 Accepted Submission(s): 5908
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
题目大意是求线段的交点个数,话不多说,直接上代码!.
```
#include
using namespace std;
const double eps=1e-10;
struct Point
{
double x,y;
};
struct Points
{
Point s,e;
} num[128];
bool inter(Point&a,Point&b,Point&c,Point&d)
{
if(min(a.x,b.x)>max(c.x,d.x)||min(a.y,b.y)>max(c.y,d.y)||min(c.x,d.x)>max(a.x,b.x)||min(c.y,d.y)>max(a.y,b.y))
return 0;
double h,i,j,k;
h=(b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
i=(b.x-a.x)*(d.y-a.y)-(b.y-a.y)*(d.x-a.x);
j=(d.x-c.x)*(a.y-c.y)-(d.y-c.y)*(a.x-c.x);
k=(d.x-c.x)*(b.y-c.y)-(d.y-c.y)*(b.x-c.x);
return h*i=0; --j)
if(inter(num[i].s,num[i].e,num[j].s,num[j].e))
sum++;
}
printf("%d\n",sum);
}
return 0;
}
```
HDU 1086的更多相关文章
- hdu 1086(计算几何入门题——计算线段交点个数)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1086 You can Solve a Geometry Problem too Time Limit: 2 ...
- 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 ...
- *HDU 1086 计算几何
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条线段,判断相交的点数. 分析:判断线段相交模板题,快速排斥实验原理就是每条线段代表的向量和该线段的一个端点 ...
- hdu 1086 You can Solve a Geometry Problem too [线段相交]
题目:给出一些线段,判断有几个交点. 问题:如何判断两条线段是否相交? 向量叉乘(行列式计算):向量a(x1,y1),向量b(x2,y2): 首先我们要明白一个定理:向量a×向量b(×为向量叉乘),若 ...
- 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 个线段找到交点个数 思路:数据量小,直接暴力判断所有线段是否相交 /*************************************************** ...
随机推荐
- mysql 开发进阶篇系列 7 锁问题(innodb锁争用情况及锁模式)
1 .获取innodb行锁争用情况 1.1 通过检查innodb_row_lock状态变量来分析系统上的行锁的争夺情况 SHOW STATUS LIKE 'innodb_row_lock%' 通过in ...
- Android--UI之ProgressBar
前言 开门见山,开篇明意.这篇博客主要讲解一下Android中ProgressBar控件以及间接继承它的两个子控件SeekBar.RatingBar的基本用法,因为其有继承关系,存在一些共有特性,所以 ...
- 通过Calendar简单解析Date日期,获取年、月、日、星期的数值
有时候项目中需要用到Date的年.月.日.星期的数值.那么解析方法如下: /**解析日期,获取年月日星期*/ private void parseDateToYearMonthDayWeek(Date ...
- Android权限大全(链接地址整理)
版权声明:本文为博主原创文章,未经博主允许不得转载. Manifest.permission https://developer.android.google.cn/reference/android ...
- Go Web:URLs
URL也是一个结构体: type URL struct { Scheme string Opaque string // encoded opaque data User *Userinfo // u ...
- Python系列:一、Python概述与环境安装--技术流ken
Python简介 Python是一种计算机程序设计语言.是一种动态的.面向对象的脚本语言,最初被设计用于编写自动化脚本(shell),随着版本的不断更新和语言新功能的添加,越来越多被用于独立的.大型项 ...
- (3)编译安装lamp三部曲之php-技术流ken
简介 php是服务器端脚本语言,我们需要使用它来提供动态的网页.接下来就来编译安装php吧. 系统环境及服务版本 centos7.5 服务器IP:172.20.10.7/28 libmcrypt-de ...
- 玩儿虫那些事(四)—— 使用curl
目录 一.爬一个简单的网站 二.模拟登录新浪 三.各种请求的发送 四.使用curl 五.模拟登录QQ空间 六.selenium的使用 七.phantomjs的使用 八.开源框架webmagic 九.开 ...
- 第一册:lesson sixty seven。
原文: The weekend. A:Hello , were you an tht butcher's? B:Yes I was. A:Were you at the butcher's too? ...
- 第一册:lesson twenty seven。
原文 :Mrs.smith's living room. Mrs.smith's living room is large. There is a television in the room. Th ...