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 个线段找到交点个数 思路:数据量小,直接暴力判断所有线段是否相交 /*************************************************** ...
随机推荐
- 使用 pandas 导出数据
import pandas as pd # In[58]: df = pd.DataFrame(houselist) # In[59]: df # In[61]: df.to_csv('lianjia ...
- mysql 开发进阶篇系列 53 权限与安全(账号管理的各种权限操作 上)
一. 概述 在了解前两篇的权限系统介绍后,这篇继续讲账号的管理,这些管理包括账号的创建,权限更改,账号删除等.用户连接数据库的第一步都是从账号创建开始. 1. 创建账号 有两种方法可以用来授权账号: ...
- flex布局常见用法小结
1,display:flex 这个在父容器中声明: 2,flex-direction:row / column 默认为横向,也在父容器中设置,定义flex布局的主轴方向:一条轴为主轴,那么另一条轴自然 ...
- Spring Boot 1.5升级2.1 主要问题汇总
我们目前工作的系统是基于Spring Boot 1.5.19.RELEASE.Spring Cloud Edgware.SR3开发的,因为一个新项目开发过程的体验,所以在考虑升级到Spring Boo ...
- 解决AssetBundle包加载预制体时,Shader显示异常的问题
现象: 预制体上的粒子效果显示为紫色方块. 原因:shader在打成AB包后与指定平台产生相关性,Editor中无法正常读取. 解决办法: 遍历所有加载的对象,重新赋值Shader 代码: //修正s ...
- python练习五—简单web应用
配置apache 我以前web开发基本都是基于java平台的,比如tomcat,servlet等等,由tomcat接收http请求,然后交给servlet处理,servlet处理完成以后把返回结果交给 ...
- zepto的构造器$
在zepto中,通过$来构造对象 $ = function(selector, context){ return zepto.init(selector, context) } 由该函数,实际上,在调 ...
- [转]VS2015 Cordova Ionic移动开发(一)
本文转自:https://www.cnblogs.com/UltimateAvalon/p/5328642.html 一.Windows环境配置 1.如果已经安装VS2015,打开[工具]-[选项]找 ...
- 类型,对象,线程栈,托管堆在运行时的关系,以及clr如何调用静态方法,实例方法,和虚方法(第二次修改)
1.线程栈 window的一个进程加载clr.该进程可能含有多个线程,线程创建的时候会分配1MB的栈空间. 如图: void Method() { string name="zhangsan ...
- Netty实战七之EventLoop和线程模型
简单地说,线程模型指定了操作系统.编程语言.框架或者应用程序的上下文中的线程管理的关键方面.Netty的线程模型强大但又易用,并且和Netty的一贯宗旨一样,旨在简化你的应用程序代码,同时最大限度地提 ...