Thirsty Professors

Thirsty Professors

时间限制:C/C++ 3秒,其他语言6秒
空间限制:C/C++ 262144K,其他语言524288K
Special Judge, 64bit IO Format: %lld

题目描述 

Dr. Orooji and Dr. Meade were lost in a desert and they were extremely thirsty. They each had a
stick so they decided that they can form a shape (e.g., “V” shape, “X” shape, etc.) facing the skies
and, when it rains, water would collect in the top part of the shape and then they can drink it; please
see the picture on the next page.
Making the shape would be easier if one person holds both sticks but neither professor was willing
to give up his stick. So, they tried to form the shape together, each holding one stick. And, we

know how coordinated the professors can be!

Given two line segments, the first line with positive slope and the second line with negative slope,
compute the area for water collection. When checking for intersecting (touching), if two points
are within 10-6 of each other, consider the points the same. 
 

输入描述:

There are two input lines, each describing a line segment. The first input line contains four integers
(0 <x1, y1, x2, y2< 1,000;x2>x1 and y2>y1), describing the first stick. The second input line
contains four integers (0 <x3, y3, x4, y4< 1,000;x4<x3 and y4>y3), describing the second stick.
Note that neither line segment will be parallel tox-axis or parallel toy-axis.

输出描述:

Print the area for water collection. Your output may have any number of digits after the decimal
point; answers within 10-5absolute or relative of the judge output will be considered correct.
Note that, as illustrated in the second Sample Input/Output, if the two line segments do not
intersect, it will not be possible for the water to collect and, as such, the output will be zero.

示例1

输入

复制

5 2 9 6
5 2 3 4

输出

复制

4.0

示例2

输入

复制

11 14 18 15
13 18 10 20

输出

复制

0.0

示例3

输入

复制

5 2 9 6
12 1 6 10

输出

复制

0.03333

说明

#include<iostream>
#include<set>
#include<cmath>
#include<cstring>
double graveity[3];
double line[10];
using namespace std;

int main(){
    double x1,y1,x2,y2,x3,y3,x4,y4;
    cin>>x1>>y1>>x2>>y2;
    cin>>x3>>y3>>x4>>y4;
    double my1=y1;
    double sy1=y1;
    double xxx,xxxx;
    double a = (y1 - y2) / (x1 - x2);
    double b = (x1 * y2 - x2 * y1) / (x1 - x2);
    if(y1<y2) {
        my1=y2;
        xxx=x2;
    }
    else {
        xxx=x1;
        sy1=y2;
    }
    //第二条
    
    double c = (y3 - y4) / (x3 - x4);
    double d = (x3 * y4 - x4 * y3) / (x3 - x4);
    double my2=y3;
    double sy2=y3;
    if(y3<y4) {
        my2=y4;
        xxxx=x4;
    }
    else {
        xxxx=x3;
        sy2=y4;
    }
      
    double x = ((x1 - x2) * (x3 * y4 - x4 * y3) - (x3 - x4) * (x1 * y2 - x2 * y1))
        / ((x3 - x4) * (y1 - y2) - (x1 - x2) * (y3 - y4));
      
    double y = ((y1 - y2) * (x3 * y4 - x4 * y3) - (x1 * y2 - x2 * y1) * (y3 - y4))
        / ((y1 - y2) * (x3 - x4) - (x1 - x2) * (y3 - y4));

    double yy;
    double xx;

    if(y>=sy1&&y>=sy2&&y<=my1&&y<=my2){
        if(my1>my2){
            yy=my2;
            xx=(double)((double)yy-(double)b)/(double)a;
            double h=abs(yy-y);
            
            double s=h*abs(xx-xxxx)/2.0;
            printf("%lf",s);
            
        }
        else{
            yy=my1;
            xx=(double)((double)yy-(double)d)/(double)c;
            double h=abs(yy-y);
            double s=h*abs(xx-xxx)/2.0;
            printf("%lf",s);
        }
    }
    else{
        cout<<"0.0";
    }
    
    
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郭晋龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值