HDoj 2056 Rectangles

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:  2057 2058 2062 2060 2059

注意两个矩形完全不相交时不能使用公式计算,直接为0

C++代码如下:

#include <iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    double x[4];
    double y[4];
    while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3]) !=EOF )
    {
        if( (min(x[0],x[1])>max(x[2],x[3]))  ||  (max(x[0],x[1])<min(x[2],x[3])) )         //首先排除两个矩形左右错开,此时面积为0
        {
            printf("0.00\n");
            continue;
        }
        if( (min(y[0],y[1])>max(y[2],y[3]))  ||  (max(y[0],y[1])<min(y[2],y[3])) )         //排除两个矩形上下错开,此时面积为0
        {
            printf("0.00\n");
            continue;
        }
        sort(x,x+4);
        sort(y,y+4);
        printf("%.2lf\n",(x[2]-x[1])*(y[2]-y[1]));
    }
}

原文地址:https://www.cnblogs.com/wzmm/p/12704621.html

时间: 2024-10-10 04:23:40

HDoj 2056 Rectangles的相关文章

HDU 2056 Rectangles(计算相交面积)

Rectangles Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 20183    Accepted Submission(s): 6537 Problem Description Given two rectangles and the coordinates of two points on the diagonals of e

HDU 2056 Rectangles

这题就是简单的几何题,刚接触ACM做这题时,不会写,当时想的太复杂了,把矩形的各种情况组合都考虑到了,结果发现这样太复杂就放弃了.今天做这道题时,我突然发现既然题目给的是对角线的坐标,为什么不用对角线之间的关系来判别矩形之间的位置关系呢?于是思路就很简单的涌现出来了.只要画个图,就能明白两者之间对角线的关系. #include<cstdio> #include<cstring> #include<algorithm> double _max(double x,doubl

杭电oj2047-2049、2051-2053、2056、2058

2047  阿牛的EOF牛肉串 1 #include<stdio.h> 2 3 int main(){ 4 int n,i; 5 _int64 s[51]; 6 while(~scanf("%d",&n)){ 7 s[1]=3;s[2]=8; 8 for(i=3;i<=n;i++){ 9 s[i] = s[i-1]*2 + s[i-2]*2; 10 } 11 printf("%I64d\n",s[n]); 12 } 13 14 15 } 2

hdoj:2056

#include <iostream> #include <iomanip> #include <cstdlib> using namespace std; struct node { double a, b, c, d; node(){} void add(double a, double b, double c, double d){ this->a = a; this->b = b; this->c = c; this->d = d; }

【HDOJ】1510 White Rectangles

这个题目很好,变形的题目也很多.简单DP. 1 /* 1510 */ 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 6 #define MAXN 105 7 8 char map[MAXN][MAXN]; 9 int dp[MAXN][MAXN]; 10 11 int min(int a, int b) { 12 return a<b ? a:b; 13 } 14 15 int ma

HDOJ 4944 FSF’s game

http://blog.csdn.net/keshuai19940722/article/details/38519681 不明真相的补一发... FSF's game Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 448    Accepted Submission(s): 215 Problem Description FSF

hdoj 1892(二维树状数组)

Problem H Time Limit : 5000/3000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Submission(s) : 8   Accepted Submission(s) : 3 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description Now I am leaving hust acm. In

【HDOJ】4328 Cut the cake

将原问题转化为求完全由1组成的最大子矩阵.挺经典的通过dp将n^3转化为n^2. 1 /* 4328 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #include <stack> 9 #include <vector>

POJ Xiangqi 4001 &amp;&amp; HDOJ 4121 Xiangqi

题目链接(POJ):http://poj.org/problem?id=4001 题目链接(HDOJ):http://acm.hdu.edu.cn/showproblem.php?pid=4121 Xiangqi Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1108   Accepted: 299 Description Xiangqi is one of the most popular two-player boa