链接:传送门

题意:给出 n 个线段找到交点个数

思路:数据量小,直接暴力判断所有线段是否相交


/*************************************************************************
> File Name: hdu1086.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年05月07日 星期日 23时34分32秒
************************************************************************/ #include<bits/stdc++.h>
using namespace std; #define eps 1e-10
struct point{ double x,y; };
struct V{ point s,e; }; 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<=eps && j*k<=eps;
}
int main(){
int n;
V vct[110];
while(~scanf("%d",&n) && n){
for(int i=0;i<n;i++) scanf("%lf%lf%lf%lf",&vct[i].s.x,&vct[i].s.y,&vct[i].e.x,&vct[i].e.y);
int cnt = 0;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if( inter(vct[i].s,vct[i].e,vct[j].s,vct[j].e) ) cnt++;
}
}
printf("%d\n",cnt);
}
return 0;
}

HDU 1086 You can Solve a Geometry Problem too( 判断线段是否相交 水题 )的更多相关文章

  1. 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 ...

  2. 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 ...

  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 ...

  4. hdu 1086 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/3 ...

  5. 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 ...

  6. hdu 1086 You can Solve a Geometry Problem too [线段相交]

    题目:给出一些线段,判断有几个交点. 问题:如何判断两条线段是否相交? 向量叉乘(行列式计算):向量a(x1,y1),向量b(x2,y2): 首先我们要明白一个定理:向量a×向量b(×为向量叉乘),若 ...

  7. 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 ...

  8. Hdoj 1086.You can Solve a Geometry Problem too 题解

    Problem Description Many geometry(几何)problems were designed in the ACM/ICPC. And now, I also prepare ...

  9. HDU 1086You can Solve a Geometry Problem too(判断两条选段是否有交点)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1086 判断两条线段是否有交点,我用的是跨立实验法: 两条线段分别是A1到B1,A2到B2,很显然,如果 ...

随机推荐

  1. HDU2035 - 人见人爱A^B

    求A^B的最后三位数表示的整数.  说明:A^B的含义是"A的B次方" Input 输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=1 ...

  2. nyoj8-一种排序

    一种排序 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 现在有很多长方形,每一个长方形都有一个编号,这个编号可以重复:还知道这个长方形的宽和长,编号.长.宽都是整数:现 ...

  3. ubuntu的安装

    前言 对计算机的学习来说,使用Linux系统是有好处的,Windows是商业的,无法学习操作系统的内在东西,所以选择折腾Linux. 我选择了ubuntu作为学习系统,Linux发行版没有什么最好之说 ...

  4. nginx反向代理时保持长连接

    ·[场景描述] HTTP1.1之后,HTTP协议支持持久连接,也就是长连接,优点在于在一个TCP连接上可以传送多个HTTP请求和响应,减少了建立和关闭连接的消耗和延迟. 如果我们使用了nginx去作为 ...

  5. hdu 1868 水

    #include<stdio.h> int main() { int n,m,i,j,k; while(scanf("%d",&n)!=EOF) { k=2; ...

  6. nodejs-mysql模块

    安装mysql模块 1 npm install -g mysql node中使用Mysql模块来执行mysql命令 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 var ht ...

  7. 关联规则推荐及Apriori算法

    参考这篇文章: http://blog.csdn.net/rongyongfeikai2/article/details/40457827 这条关联规则的支持度:support = P(A并B) 这条 ...

  8. 经验总结21--抓取WEB数据,汇率,HtmlAgilityPack

    网上找了非常多资料,PHP的比較多,然后找到有csv文件的.处理起来非常麻烦,国外的站点速度非常慢. 最后还是去页面上抓取数据,我是从中国银行抓取的,各位可去其它站点抓取. 1.模拟请求URL. st ...

  9. UESTC--1272--Final Pan's prime numbers(水题)

    Final Pan's prime numbers Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & % ...

  10. Java-MyBatis:MyBatis XML 文件

    ylbtech-Java-MyBatis:MyBatis XML 文件 1.返回顶部 1. Mapper XML 文件 MyBatis 的真正强大在于它的映射语句,也是它的魔力所在.由于它的异常强大, ...