HDUOJ1086You 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): 6340 Accepted Submission(s): 3064
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.
- #include<stdio.h>
- #include<math.h>
- const double eps=1e- ;
- typedef struct
- {
- double x,y;
- }point;
- double min(double a, double b)
- {
- return a<b?a:b;
- }
- double max(double a,double b)
- {
- return a>b?a:b;
- }
- //判断线段是否有焦点
- 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 ;
- 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<=eps&&j*k<=eps;
- };
- point st[],en[];
- int main()
- {
- int n,j,i,cnt=;
- while(scanf("%d",&n),n)
- {
- cnt=;
- for( i= ; i<n ; i++ )
- scanf("%lf%lf%lf%lf",&st[i].x,&st[i].y,&en[i].x,&en[i].y);
- for( i= ; i<n ; i++ )
- {
- for(j=i+ ; j<n ;j++ )
- {
- if(inter(st[i],en[i],st[j],en[j]))
- cnt++;
- }
- }
- printf("%d\n",cnt);
- }
- return ;
- }
HDUOJ1086You can Solve a Geometry Problem too的更多相关文章
- 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 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 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
pid=1086">You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Mem ...
- 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 ...
- (叉积,线段判交)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 ...
- 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 ...
随机推荐
- linux统计文件夹内文件数
for dir in `find ./ -type d ` ;do echo -n "$dir " ;find $dir -type f | wc -l ;echo " ...
- 局域网Cesium离线影像及瓦片影像地图加载【转】
http://www.mamicode.com/info-detail-2161992.html 1.Cesium简介 优点: cesium展示地图数据效果比较好,解析2D地图各种不同服务类型的数据源 ...
- iOS开发-UIApplication和App启动状态
UIApplication简单从字面上了解就是应用程序,开发的时候有的时候会根据需要调用其中的方法,看起来不起眼,实际在iOS开发UIApplication提供了iOS程序运行期间的控制和协作工作.每 ...
- Volley框架的介绍使用
Volley是在2013年的Google I/O 2013大会上发布的,是我们的网络通信更快,更简单,更方便.对于初学者来讲是一个很好的框架. 简单来说,它提供了如下的便利功能: JSON,图像等的异 ...
- Android -- 程序启动画面 Splash
很多应用都会有一个启动界面.欢迎画面慢慢隐现,然后慢慢消隐. 我的方式是使用两个Activity,程序启动时候load第一张Activity,然后由tick触发N秒钟后startActivity另外一 ...
- 【5】基于Log4Net的日志系统
阅读目录 日志系统应具备的特性 Log4Net 配置文件:log4net.config 初始化 输出信息 对Log4Net的封装 log4net.config复杂配置 不管是Web应用程序还是W ...
- 你使用 Web 平台安装程序命令行工具
你使用 Web 平台安装程序命令行工具 获取的软件由其所有者授权给你.Microsoft 未授予你第三方软件的任何权利.已成功加载主源: https://go.microsoft.com/?linki ...
- 一款纯css实现的垂直时间线效果
今天给大家分享一款纯css实现的垂直时间线效果.垂直时间线适合放在类似任务时间安排的网页上.该实现采用了蓝色作为主题色,界面效果还不错.一起看下效果图: 实现的代码. html代码: ... 阅读原文 ...
- C#.NET常见问题(FAQ)-浮点数如何四舍五入
使用Math.Round方法即可实现保留指定的小数点后面位数,这种方法返回的还是double类型,而ToString方法并没有做实际转换 更多教学视频和资料下载,欢迎关注以下信息: 我的优酷空间: ...
- 高可用性(HA) 4 - network bonding
我们都知道,hadoop namenode是一个臭名昭著的单点故障点(SPOF). 当你找到一篇High Availability的文章, 以为使用heartbeat/pacemaker, coro ...