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. Extjs中创建Tree菜单【一】

    此篇treepanel的描写是很简单,没有太大的难度,在学习时,可以先熟悉tree的一些配置信息.属性.方法和事件. 然后先写一个简单的例子,慢慢了解从中如何实现的,然后在慢慢的深入了解,实现一些复杂 ...

  2. JavaWeb与Asp.net工作原理比较分析

    一.概述 不管是什么语言开发的web应用程序,都是在解决一个问题,那就是用户输入url怎么把对应的页面响应出来,如何通过url映射到响应的类,由于自己做asp.net的时间也不短了,还算是对asp.n ...

  3. Android学习总结(十五) ———— Notification(状态栏通知)基本用法

    一.Notification基本概念  Notification是一种具有全局效果的通知,它展示在屏幕的顶端,首先会表现为一个图标的形式,当用户向下滑动的时候,展示出通知具体的内容.我们在用手机的时候 ...

  4. Android: Toolbar、AppBarLayout

    ToolBar是google退出的一个应用程序动作条 包括: 设置导航栏图标 设置应用程序Logo 设置标题 设置子标题 添加各种自定义控件 添加动作条菜单 API:https://developer ...

  5. 关于struts2中的default-action-ref

    struts2中的default-action-ref一般用于,在请求无效或错误时将请求指引到错误页面.我这次的用法是在请求首页之前先发送请求到后台,进行数据获取后再转至首页显示,但是出了一个问题,d ...

  6. C++获取字符cin,getchar,get,getline的区别

    原创作品,转载请注明来源:http://www.cnblogs.com/shrimp-can/p/5241544.html 1.cin>> 1)最常见的是获取输入的一个字符或数字,如 in ...

  7. xgboost-python参数深入理解

    由于在工作中应用到xgboost做特征训练预测,因此需要深入理解xgboost训练过程中的参数的意思和影响. 通过search,https://www.analyticsvidhya.com/blog ...

  8. Linux之nc命令详解

    nc是一个强大的网络工具,可以通过yum安装 [root@LB2 ~]# which nc /usr/bin/which: no nc in (/usr/local/sbin:/usr/local/b ...

  9. Jmeter新建用例图示

    添加线程组   添加HTTP请求   编辑HTTP请求 添加HTTP信息头   编辑HTTP信息头 添加断言   添加查看结果树   添加聚合报告   添加响应时间   添加TPS   批量运行命令: ...

  10. 机器学习:Python实现单层Rosenblatt感知器

    如果对Rosenblatt感知器不了解,可以先查看下相关定义,然后对照下面的代码来理解. 代码中详细解释了各步骤的含义,有些涉及到了数学公式的解释. 这篇文章是以理解Rosenblatt感知器的原理为 ...