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/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8861 Accepted Submission(s): 4317
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.
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
#include<cstdio>
#include<cmath>
using namespace std;
#define eps 1e-6
#define N 105
struct point{
double x , y ;
point(double x_, double y_){
x = x_;
y = y_;
}
point(){}
point operator - (const point a) const
{
return point(x-a.x,y-a.y);
}
double operator * (const point a) const
{
return x*a.y - a.x*y;
}
}; struct line{
point s , t;
}L[N]; int main()
{
int T;
while(~scanf("%d",&T),T)
{
for(int i = ;i < T ; i++)
{
scanf("%lf%lf%lf%lf",&L[i].s.x,&L[i].s.y,&L[i].t.x,&L[i].t.y);
}
int ans = ;
for(int i = ; i < T ; i++)
{
for(int j = i+ ; j < T ; j++)//j从i开始保证不会重复判断
{
// if(i==j) continue;
point A = L[i].s;
point B = L[i].t;
point C = L[j].s;
point D = L[j].t;
if((((D-C)*(A-C))*((D-C)*(B-C)))>eps) {continue;}
if((((D-A)*(B-A))*((C-A)*(B-A)))>eps) {continue;}
ans++;
}
}
printf("%d\n",ans);
}
return ;
}
也可以把他们写成函数在外面
#include <cstdio>
#include <cmath>
using namespace std;
#define eps 1e-8
#define N 105
struct point{
double x, y;
point(){}
point(double _x, double _y) {
x = _x, y = _y;
} point operator - (point a){
return point(x-a.x, y-a.y);
} double operator * (point a){
return x*a.y - y*a.x;
}
}; struct line{
point s, t;
}L[N]; bool ck(line a, line b)
{
point A = a.s, B = a.t, C = b.s, D = b.t;
if(((C-A)*(B-A)) *((D-A)*(B-A)) > eps) return false;
if(((A-C)*(D-C)) *((B-C)*(D-C)) > eps) return false;
return true;
} int main()
{
int n;
while(~scanf("%d", &n), n)
{
for(int i = ; i < n; i++)
scanf("%lf %lf %lf %lf", &L[i].s.x, &L[i].s.y, &L[i].t.x, &L[i].t.y);
int cnt = ;
for(int i = ; i < n; i++)
for(int j = i+; j < n; j++)
cnt += ck(L[i], L[j]);
printf("%d\n", cnt);
}
}
You can Solve a Geometry Problem too(线段求交)的更多相关文章
- hdu 1086 You can Solve a Geometry Problem too [线段相交]
题目:给出一些线段,判断有几个交点. 问题:如何判断两条线段是否相交? 向量叉乘(行列式计算):向量a(x1,y1),向量b(x2,y2): 首先我们要明白一个定理:向量a×向量b(×为向量叉乘),若 ...
- 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 ...
- (叉积,线段判交)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 ...
- 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
pid=1086">You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Mem ...
随机推荐
- [置顶]
Xamarin android中使用signalr实现即时通讯
前面几天也写了一些signalr的例子,不过都是在Web端,今天我就来实践一下如何在xamarin android中使用signalr,刚好工作中也用到了这个,也算是总结一下学到的东西吧,希望能帮助你 ...
- node.js stream
stream是一个接口,流是可以从一个读取或写入数据的目标对象 ,Node 中有很多对象实现了这个接口 一.nodejs stream类型 1. Readable - 可读操作. Writable ...
- [编织消息框架][网络IO模型]Netty Reactor
严格来讲Netty Reactor是一种设计模式,一听模式两字就知道了吧,套路哈哈 Reactor中文译为“反应堆”. 看图netty处理流程 1.netty server 至少有两组reactor. ...
- java log4j基本配置及日志级别配置详解
java log4j日志级别配置详解 1.1 前言 说出来真是丢脸,最近被公司派到客户公司面试外包开发岗位,本来准备了什么redis.rabbitMQ.SSM框架的相关面试题以及自己做过的一些项目回顾 ...
- 房上的猫:HTML5基础
一.W3C标准 1)W3C标准不是某一个标准,而是一系列的标准的集合,一个网页主要由三部分组成,即结构(Structure),表现(Presentation)和行为(Behavior) 2)不很严谨的 ...
- js设置元素class方法小结及classList相关
给DOM元素设置class是我们在项目中非常容易遇到的,网上的资料和总结也比较多,下面比较全面的整理一下,希望给到大家一些帮助!并引用两种成熟的classList的兼容方法 一.el.setA ...
- 深入理解cookie和session
cookie和session在java web开发中扮演了十分重要的作用,本篇文章对其中的重要知识点做一些探究和总结. 1.cookie存在于浏览器 随意打开一个网址,用火狐的调试工具,随意选取一个链 ...
- Mongodb高级查询【二】
上一篇文章,写了mongodb常规操作,继续写入,本章主要讲高级查询,文本,聚集,大数据查询. Mongodb的查询语法是很多的,是NOSQL队伍中比较丰富的一个.当然有很多查询跟关系型查询无法相比. ...
- [树莓派(raspberry pi)] 02、PI3安装openCV开发环境做图像识别(详细版)
前言 上一篇我们讲了在linux环境下给树莓派安装系统及入门各种资料 ,今天我们更进一步,尝试在PI3上安装openCV开发环境. 博主在做的过程中主要参考一个国外小哥的文章(见最后链接1),不过其教 ...
- H5前端性能测试总结
测试关注指标 Http请求个数 同一个域名不同浏览器内核.不同版本浏览器,大部分并发请求数是6个: 优化方案: a.雪碧图:即CSS Sprite,也称CSS精灵,是一种CSS图像合并技术,该方法是将 ...