Rectangles

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 19299    Accepted Submission(s): 6255

Problem Description

Given two rectangles and the coordinates of two points on the diagonals of each rectangle,you have to calculate the area of the intersected part of two rectangles. its sides are parallel to OX and OY .

Input

Input The first line of input is 8 positive numbers which indicate the coordinates of four points that must be on each diagonal.The 8 numbers are x1,y1,x2,y2,x3,y3,x4,y4.That means the two points on the first rectangle are(x1,y1),(x2,y2);the other two points on the second rectangle are (x3,y3),(x4,y4).

Output

Output For each case output the area of their intersected part in a single line.accurate up to 2 decimal places.

Sample Input

1.00 1.00 3.00 3.00 2.00 2.00 4.00 4.00
5.00 5.00 13.00 13.00 4.00 4.00 12.50 12.50

Sample Output

1.00
56.25

Author

seeyou

Source

校庆杯Warm Up

Recommend

linle   |   We have carefully selected several similar problems for you:  20572058206220602059

Statistic | Submit | Discuss | Note

这道题乍一看挺复杂,但是是有技巧的。只需要将4个横坐标和4个纵坐标排序然后就可简化成一种很容易计算的形式。还要注意首先要排除没有交叉部分的情况。

 #include<stdio.h>
#include<algorithm>
using namespace std; int main()
{
double x[], y[];
while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x[], &y[], &x[], &y[], &x[], &y[], &x[], &y[])) {
double minx1 = min(x[], x[]), maxx1 = max(x[], x[]), minx2 = min(x[], x[]), maxx2 = max(x[], x[]);
double miny1 = min(y[], y[]), maxy1 = max(y[], y[]), miny2 = min(y[], y[]), maxy2 = max(y[], y[]);
if(minx1 >= maxx2 || maxx1 <= minx2 || maxy1 <= miny2 || miny1 >= maxy2) printf("%.2lf\n", );
else {
sort(x, x + );
sort(y, y + );
printf("%.2lf\n", (x[] - x[]) * (y[] - y[]));
}
}
}

HDU2056(rectangles)的更多相关文章

  1. HDU100题简要题解(2050~2059)

    HDU2050 折线分割平面 题目链接 Problem Description 我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目.比如,一条折线可以 ...

  2. poj-1314 Finding Rectangles

    题目地址: http://poj.org/problem?id=1314 题意: 给出一串的点,有些点可以构成正方形,请按照字符排序输出. 因为这道题的用处很大, 最近接触的cv 中的Rectangl ...

  3. [ACM_暴力][ACM_几何] ZOJ 1426 Counting Rectangles (水平竖直线段组成的矩形个数,暴力)

    Description We are given a figure consisting of only horizontal and vertical line segments. Our goal ...

  4. codeforces 713B B. Searching Rectangles(二分)

    题目链接: B. Searching Rectangles time limit per test 1 second memory limit per test 256 megabytes input ...

  5. White Rectangles[HDU1510]

    White Rectangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. Java基础之在窗口中绘图——绘制直线和矩形(Sketcher 2 drawing lines and rectangles)

    控制台程序. import javax.swing.JComponent; import java.util.*; import java.awt.*; import java.awt.geom.*; ...

  7. Counting Rectangles

    Counting Rectangles Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1043 Accepted: 546 De ...

  8. UVA 10574 - Counting Rectangles 计数

    Given n points on the XY plane, count how many regular rectangles are formed. A rectangle is regular ...

  9. Project Euler 85 :Counting rectangles 数长方形

    Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...

随机推荐

  1. EXCEL表格常用函数使用的难点

    1.  INDIRECT(ref_text,逻辑值) 返回由文本字符串指定的引用.此函数立即对引用进行计算,并显示其内容.ref_text,文本引用说明, (1) A1-样式的引用(逻辑值,T,缺省) ...

  2. Linq101-Element

    using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Element ...

  3. Mac下配置node.js 和react-native

    最近对JS挺感兴趣的,就琢磨着在mac上配置下环境学习学习,正巧看到了Facebook的react-native,顺便配置了一下. 安装Homebrew 终端输入: ruby -e "$(c ...

  4. 创建cocos项目

    创建cocos项目 进入终端输入命令: cocos new HelloCpp -p com.cocos.org -l cpp -d /Users/emerys/documents/cocos 参数说明 ...

  5. Swift - 28 - 内部参数名和外部参数名

    //: Playground - noun: a place where people can play import UIKit // 外部参数的作用是为了让程序员调用代码的时候能清晰的看出所传参数 ...

  6. Java Calendar 计算时间差

    public static void main(String[] args) { Calendar c=Calendar.getInstance(); int y=2016;//年 int M=1;/ ...

  7. 爬虫爬oj用户头像

    import requests import Queue import urllib import urllib2 import re import requests alreadyImg = set ...

  8. 【USACO 2.4.2】穿越栅栏

    [描述] 农夫John在外面的田野上搭建了一个巨大的用栅栏围成的迷宫.幸运的是,他在迷宫的边界上留出了两段栅栏作为迷宫的出口.更幸运的是,他所建造的迷宫是一个“完美的”迷宫:即你能从迷宫中的任意一点找 ...

  9. 制作chm格式的帮助文档

    学习java的人都用过jdk帮助文档,借助工具我们也可以自己生成chm格式的帮助文档, 原文:http://www.cnblogs.com/shenliang123/archive/2012/04/2 ...

  10. jquery 工作空间注册

    在一些面向对象的语言中有命名空间的概念,好处就是把不同的类放在不同的文件夹下面,这样就不会发生命名冲突,当然命名空间还有其他的作用. 在这里我们讨论的是在JS中怎么使用命名空间.当然JS并没有提供原生 ...