| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 787 人关注过本帖
标题:hdu 的 2056 求矩形相交面积 !!球告知哪里错了,射射!
只看楼主 加入收藏
laybaek
Rank: 2
等 级:论坛游民
帖 子:20
专家分:50
注 册:2014-10-21
结帖率:100%
收藏
已结贴  问题点数:15 回复次数:4 
hdu 的 2056 求矩形相交面积 !!球告知哪里错了,射射!
#include<stdio.h>

    double max(double a,double b)
    {return a>b?a:b;}
    double min(double a,double b)
    {return a<b?a:b;}
 int main()
{
    double x1,y1,x2,y2,x3,y3,x4,y4;
    double s;
    while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)!=EOF)
    {
    if((min(x2,x4)-max(x1,x3)>=0)&& (min(y2,y4)-max(y1,y3)>=0))
        {
        s=(min(x2,x4)-max(x1,x3))* (min(y2,y4)-max(y1,y3));
        printf("%.2lf\n",s);
        }
    else
    printf("0.00\n");
    }
    return 0;
}
数据测试是对的 但是提交wa 求助哪里错了 射射!!
搜索更多相关主题的帖子: include double return 
2014-11-13 20:58
laybaek
Rank: 2
等 级:论坛游民
帖 子:20
专家分:50
注 册:2014-10-21
收藏
得分:0 
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




这个是题目!
2014-11-13 20:59
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:15 
“Given two rectangles and the coordinates of two points on the diagonals of each rectangle”

这里只说了是对角线上的点,但没说是哪条对角线。所以不要假设x1<x2这样的条件。

程序代码:
#include<stdio.h>
int main()
{
    double x1, y1, x2, y2, x3, y3, x4, y4, x, y;
    while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4) != EOF)
    {
        if(x1 > x2){ x = x1; x1 = x2; x2 = x;}
        if(y1 > y2){ y = y1; y1 = y2; y2 = y;}
        if(x3 > x4){ x = x3; x3 = x4; x4 = x;}
        if(y3 > y4){ y = y3; y3 = y4; y4 = y;}
        x = (x4 > x2) ? x2 : x4;
        x -= (x3 > x1) ? x3 : x1;
        y = (y4 > y2) ? y2 : y4;
        y -= (y3 > y1) ? y3 : y1;
        if(x <= 0 || y <= 0)
            printf("0.00\n");
        else
            printf("%.2f\n", x * y);
    }
    return 0;
}

重剑无锋,大巧不工
2014-11-13 21:09
laybaek
Rank: 2
等 级:论坛游民
帖 子:20
专家分:50
注 册:2014-10-21
收藏
得分:0 
回复 3 楼 beyondyf
原来是这样 超感谢!
2014-11-13 21:35
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
不客气,以后尽量少打错别字。

重剑无锋,大巧不工
2014-11-13 21:48
快速回复:hdu 的 2056 求矩形相交面积 !!球告知哪里错了,射射!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024450 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved