You can Solve a Geometry Problem too

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8693    Accepted Submission(s): 4232

Problem Description
Many geometry(几何)problems were designed in the ACM/ICPC. And now, I also prepare a geometry problem for this final exam. According to the experience of many ACMers, geometry problems are always much trouble, but this problem is very easy, after all we are now attending an exam, not a contest :)
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. 

 
Input
Input contains multiple test cases. Each test case contains a integer N (1=N<=100) in a line first, and then N lines follow. Each line describes one segment with four float values x1, y1, x2, y2 which are coordinates of the segment’s ending. 
A test case starting with 0 terminates the input and this test case is not to be processed.
 
Output
For each case, print the number of intersections, and one line one case.
 
Sample Input
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
 
Sample Output
1
3
 
Author
lcy
 
 
 
仅仅用到了相交线段模板
 
 
 
 #include <iostream>
#include <cmath> using namespace std; struct POINT
{
double x;
double y;
};
struct LINESEG
{
POINT s;
POINT e;
}; double multiply(POINT a,POINT b,POINT c)
{
  return ((b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y));
}
bool intersect(LINESEG u,LINESEG v)
{
  return( (max(u.s.x,u.e.x)>=min(v.s.x,v.e.x))&& //排斥实验
    (max(v.s.x,v.e.x)>=min(u.s.x,u.e.x))&&
    (max(u.s.y,u.e.y)>=min(v.s.y,v.e.y))&&
    (max(v.s.y,v.e.y)>=min(u.s.y,u.e.y))&&
    (multiply(v.s,u.e,u.s)*multiply(u.e,v.e,u.s)>=)&& //跨立实验
    (multiply(u.s,v.e,v.s)*multiply(v.e,u.e,v.s)>=));
}
int main()
{   int N;
  while(cin>>N&&N)
  {
    LINESEG A[];
    int count=;
    for(int i=;i<N;i++)
    {
      cin>>A[i].s.x>>A[i].s.y>>A[i].e.x>>A[i].e.y;
    }
    for(int i=;i<N;i++)
    for(int j=;j<N;j++)
    if(intersect(A[i],A[j])&&i!=j)
      count++;
    cout<<count/<<endl;
  }
48 return ;
49 }

【HDOJ 1086】 模板水过的更多相关文章

  1. HDOJ(2056)&HDOJ(1086)

    Rectangles    HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...

  2. 最小费用最大流模板 poj 2159 模板水题

    Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15944   Accepted: 8167 Descr ...

  3. 2015百度之星1002 查找有序序列(RMQ+主席树模板水过)

    题意:求在数列中能找到几个个长度为k 的区间,里面的 k 个数字排完序后是连续的. 思路:枚举范围,判断区间内是否有重复的数字(主席树),没有的话求区间最大-区间最小(RMQ),判断是否等于K,是的话 ...

  4. HDOJ 1070 Milk(水题,考英文的)

    Problem Description Ignatius drinks milk everyday, now he is in the supermarket and he wants to choo ...

  5. hdu 2642 二维树状数组 单点更新区间查询 模板水题

    Stars Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others) Total Subm ...

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

  7. HDOJ 5387 Clock 水+模拟

    Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Subm ...

  8. 【POJ 2104】 K-th Number 主席树模板题

    达神主席树讲解传送门:http://blog.csdn.net/dad3zz/article/details/50638026 2016-02-23:真的是模板题诶,主席树模板水过.今天新校网不好,没 ...

  9. HDU5012:Dice(bfs模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 Problem Description There are 2 special dices on the ...

随机推荐

  1. 【mac版】前端开发工具整理

    整理了一些日常工作中涉及到的工具,下载链接:https://pan.baidu.com/s/1kUD60a7#list/path=%2F 编辑器 Webstorm 软件下载及常用操作 webstorm ...

  2. Git基础教程(一)

    本教程为学习笔记,github作为最受欢迎的资源库,不可不学!详细教程参见:廖雪峰的官方网站Git教程系列.准备花两篇幅搞定实战总结,闲言碎语少说,脚踏实地求真! 1,Git入门       Git是 ...

  3. 多线程爬坑之路--并发,并行,synchonrized同步的用法

    一.多线程的并发与并行: 并发:多个线程同时都处在运行中的状态.线程之间相互干扰,存在竞争,(CPU,缓冲区),每个线程轮流使用CPU,当一个线程占有CPU时,其他线程处于挂起状态,各线程断续推进. ...

  4. ajax基础部分

    今天讲了ajax的组成及使用方法:首先我们看看一个简单的ajax的例子: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transition ...

  5. CDIF: 基于JSON的SOA软件框架

    通用设备互联框架(CDIF)是一个具备中美知识产权保护的,基于web的连接框架,目前有部分开源实现存放在: GitHub - out4b/cdif: Common device interconnec ...

  6. a中的类型转换

    自动类型转换 当然自动类型转换是需要满足特定的条件的: 1.  目标类型能与源类型兼容,如 double 型兼容 int 型,但是 char 型不能兼容 int 型. 2.  目标类型大于源类型,如 ...

  7. loadrunner:判断是否服务器连接池瓶颈

    分析Web Resources中的Connections per second可以判断是否服务器连接池瓶颈. connections per second会给出两种不同状态的连接数:中断的连接和新建的 ...

  8. QT 中使用 c++ 的指针

    之前没有接触过 c++,不过听说 c++ 的指针很坑,直到最近在用 QT / C++ 写一个 Linux Deepin 系统上检测网络流量和网速的小程序时,发现 c++ 的指针用起来真的特别蛋疼. 不 ...

  9. css中设置div垂直水平居中的方法

    设置要水平垂直居中的div的position为absolute,left:50%;margin-left为负的这个元素宽度的一半,同理,top:50%;margin-top为负的这个元素的高度的一半. ...

  10. android:layout_gravity和android:gravity属性的区别1

    一.介绍: gravity的中文意思就是"重心",就是表示view横向和纵向的停靠位置 (1).android:gravity:是对view控件本身来说的,是用来设置view本身的 ...