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. Java日志工具之SLF4J

    SLF4J全称为Simple Logging Facade for Java (简单日志门面),作为各种日志框架的简单门面或者抽象,包括 java.util.logging, log4j, logba ...

  2. Visual Studio 20周年,我和VS不得不说的故事(内含福利)

    Visual Studio 2017正式版已如期发布(点击这里查看发布全记录)!自去年 11 月正式宣布 Visual Studio 项目之后,微软终于正式推出了“宇宙最强集成开发环境(IDE)”的最 ...

  3. Java数据结构之Map学习总结

    前言: 前面学习总结了List的使用及效率对比,今天总结学习一下键值映射关系Map,顺便学习一下Android中使用Map需要注意哪些,以及谷歌官方针对Android对Map做了哪些优化. 先了解下M ...

  4. ER图是啥?

    文章转载自「开发者圆桌」一个关于开发者入门.进阶.踩坑的微信公众号 E-R图也称实体-联系图(Entity Relationship Diagram),提供了表示实体类型.属性和联系的方法,用来描述现 ...

  5. Macaca 自动化框架 [Python 系列]

    介绍 Macaca是一套完整的自动化测试解决方案,基于node.js开发.由阿里巴巴公司开源: 地址:http://macacajs.github.io/macaca/ 特点: 同时支持PC端和移动端 ...

  6. 关于使用lazytag的线段树两种查询方式的比较研究

    说到线段树,想来大家并不陌生——最基本的思路就是将其规划成块,然后只要每次修改时维护一下即可. 但是尤其是涉及到区间修改时,lazytag的使用往往能够对于程序的质量起到决定性作用(Ex:一般JSOI ...

  7. BeagleBone Black安装小米随身WiFi驱动方法

    以下操作直接在beaglebone black上执行 下载驱动源码 git clone https://github.com/rcn-ee/mt7601u.git 下载linux-headers,这是 ...

  8. 计算机程序的思维逻辑 (74) - 并发容器 - ConcurrentHashMap

    本节介绍一个常用的并发容器 - ConcurrentHashMap,它是HashMap的并发版本,与HashMap相比,它有如下特点: 并发安全 直接支持一些原子复合操作 支持高并发.读操作完全并行. ...

  9. CSS 去掉点li 的点

    转:http://blog.sina.com.cn/s/blog_63b13c300100jyek.html 方法一: <ul> <li style="list-style ...

  10. 【学习笔记】TCP通信的细节及TCP连接对HTTP事务处理性能影响

    从三次握手的细节说起 刚开始尝试使用java等后端语言写IO流,或用套接字(socket)实现简单C/S通信的同学们,常常会接触到的一个概念:就是所谓的"三次握手",socket作 ...