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 个线段找到交点个数 思路:数据量小,直接暴力判断所有线段是否相交 /*************************************************** ...
随机推荐
- 全网最详细的如何在谷歌浏览器里正确下载并安装Postman【一款功能强大的网页调试与发送网页HTTP请求的Chrome插件】(图文详解)
不多说,直接上干货! 想必,玩过Java Web的你,肯定是对于http post和get等请求测试的过程记忆犹新吧. Postman的安装方法分好几种,主要分为两种安装模式介绍: (1)chrome ...
- HDU 1006 Digital Roots
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
- 【EF6学习笔记】(三)排序、过滤查询及分页
本篇原文地址:Sorting, Filtering, and Paging 说明:学习笔记参考原文中的流程,为了增加实际操作性,并能够深入理解,部分地方根据实际情况做了一些调整:并且根据自己的理解做了 ...
- Go内建函数copy
Go内建函数copy: func copy(dst, src []Type) int 用于将源slice的数据(第二个参数),复制到目标slice(第一个参数). 返回值为拷贝了的数据个数,是len( ...
- eclipse导入的项目resource包被当做成文件夹
项目中遇到的问题: 导出的项目(错误) 原本应该是这样的 需要这样设置一下: 1 2 最后就变回来了!
- [React] react.js的一些库和用法
React性能优化 记录一次利用 Timeline/Performance工具进行 React性能优化的真实案例 http://www.jianshu.com/p/9b0e9ef0a607 React ...
- NPOI导出EXCEL报_服务器无法在发送 HTTP 标头之后追加标头
虽然发表了2篇关于NPOI导出EXCEL的文章,但是最近再次使用的时候,把以前的代码粘贴过来,居然报了一个错误: “服务器无法在发送 HTTP 标头之后追加标头” 后来也查询了很多其他同学的文章,都没 ...
- C#实现给图片加边框的方法
Bitmap bit= new Bitmap(@"" + Path);//给图片加边框 //Bitmap bit = new Bitmap(Screen.AllScreens[0] ...
- IE console.log 调试状态
最近项目遇到问题,发现alert一个弹窗,在IE中,打开开发人员工具后,可以弹出,但是不打开无法弹出,最后发现是console.log的原因,注释掉console相关的代码,问题就解决了 有些版本的I ...
- [日常] PHP库函数fgetss的BUG
1. fgetss函数php官网的解释是: (PHP 4, PHP 5, PHP 7) fgetss — 从文件指针中读取一行并过滤掉 HTML 标记 2. 测试后出现的问题是: 当文本中有一行数据 ...