来源 poj2826

It's raining outside. Farmer Johnson's bull Ben wants some rain to water his flowers. Ben nails two wooden boards on the wall of his barn. Shown in the pictures below, the two boards on the wall just look like two segments on the plane, as they have the same width.

Your mission is to calculate how much rain these two boards can collect.

Input

The first line contains the number of test cases.

Each test case consists of 8 integers not exceeding 10,000 by absolute value, x 1, y 1, x 2, y 2, x 3, y 3, x 4, y 4. ( x 1, y 1), ( x 2, y 2) are the endpoints of one board, and ( x 3, y 3), ( x 4, y 4) are the endpoints of the other one.

Output

For each test case output a single line containing a real number with precision up to two decimal places - the amount of rain collected.

Sample Input

2

0 1 1 0

1 0 2 1

0 1 2 1

1 0 1 2

Sample Output

1.00

0.00

问你在雨落下来,能接到水的面积是多少;

要分几种不可能的情况,1是不相交,2是相交但是有一根覆盖在另一个上面,3是有低于或者等于水平面的棍子

要加EPS

傻逼题目,疯狂wa,加了eps也wa,后面重写,然后交G++还wa,C++过了,cnm

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<queue>
#include<stack>
#include <iomanip>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+100;
const double eps=1e-6;
const double pi=acos(-1.0);
const int inf=0xfffffff;
using namespace std;
const double EPS=1e-6;
struct point
{
double x,y;
};
struct line
{
point a,b;
};
bool judge(line n)
{
if(n.a.y==n.b.y) return true;
return false;
}
point operator -(point m,point n)
{
point c;
c.x=m.x-n.x;
c.y=m.y-n.y;
return c;
}
point operator +(point m,point n)
{
point c;
c.x=m.x+n.x;
c.y=m.y+n.y;
return c;
}
point operator * (point c,int t)
{
point m;
m.x=c.x*t;
m.y=c.y*t;
return m;
}
double operator /(point m,point n)
{
return m.x *n.y-m.y*n.x;
}
bool cross(line n,line m)
{
if(((n.a-m.a)/(m.b-m.a))*((n.b-m.a)/(m.b-m.a))<=0
&& ((m.a-n.a)/(n.b-n.a))*((m.b-n.a)/(n.b-n.a))<=0)
return true;
else return false;
}
point jiaop(line m,line n)
{
point o;
double t=fabs((n.a-m.a)/(n.b-m.a))/fabs((m.b-m.a)/(n.b-n.a));
o=m.a;
o.x+=(m.b.x-m.a.x)*t;
o.y+=(m.b.y-m.a.y)*t;
return o;
}
point maxp(line n)
{
return n.a.y>n.b.y?n.a:n.b;
}
int main()
{
int re;
cin>>re;
while(re--)
{
line m,n;
cin>>m.a.x>>m.a.y>>m.b.x>>m.b.y;
cin>>n.a.x>>n.a.y>>n.b.x>>n.b.y;
if(judge(n)||judge(m))
{ pf("0.00\n");continue; }
else if(!cross(m,n)) { pf("0.00\n");continue; }
double k1=(m.b.y-m.a.y)/(m.b.x-m.a.x),k2=(n.b.y-n.a.y)/(n.b.x-n.a.x);
if(k1==k2) { pf("0.00\n");continue; }
point t,a,b;
int num=0;
t=jiaop(m,n);
if(t.y<m.a.y) num++;if(t.y<m.b.y) num++;if(t.y<n.a.y) num++;if(t.y<n.b.y) num++;
if(num<2) { pf("0.00\n");continue; }
if(k1*k2>0)//判断是否会覆盖
{
if(k1>0)
{
if(k1>k2)
{
if(max(m.a.x,m.b.x)>=max(n.a.x,n.b.x))
{
cout<<"0.00"<<endl;
continue;
}
}
else
{
if(max(n.a.x,n.b.x)>=max(m.a.x,m.b.x))
{
cout<<"0.00"<<endl;
continue;
}
}
}
else
{
if(k1<k2)
{
if(min(m.a.x,m.b.x)<=min(n.a.x,n.b.x))
{
cout<<"0.00"<<endl;
continue;
}
}
else
{
if(min(n.a.x,n.b.x)<=min(m.a.x,m.b.x))
{
cout<<"0.00"<<endl;
continue;
}
}
}
}
a=maxp(m);b=maxp(n);
double ans;
if(a.y>b.y)
{
if(fabs(a.x-t.x)<eps)
ans=fabs(b.x-t.x)*(b.y-t.y)/2;
else
{
double k=(a.y-t.y)/(a.x-t.x); ///a[1]->it的斜率
double q=a.y-k*a.x;
double x=(b.y-q)/k; //a[1]->it上纵坐标为a[2].y的横坐标
ans=fabs(b.y-t.y)*fabs(b.x-x)/2;
}
}else
{
if(fabs(b.x-t.x)<eps)
ans=fabs(a.x-t.x)*(a.y-t.y)/2;
else
{
double k=(b.y-t.y)/(b.x-t.x); ///a[1]->it的斜率
double q=b.y-k*b.x;
double x=(a.y-q)/k; //a[1]->it上纵坐标为a[2].y的横坐标
ans=fabs(a.y-t.y)*fabs(a.x-x)/2;
}
}
pf("%.2lf\n",ans+EPS);
}
}

H - An Easy Problem?!的更多相关文章

  1. An easy problem

    An easy problem Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  2. UVa 11991:Easy Problem from Rujia Liu?(STL练习,map+vector)

    Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...

  3. POJ 2826 An Easy Problem?!

    An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7837   Accepted: 1145 ...

  4. hdu 5475 An easy problem(暴力 || 线段树区间单点更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...

  5. [UVA] 11991 - Easy Problem from Rujia Liu? [STL应用]

    11991 - Easy Problem from Rujia Liu? Time limit: 1.000 seconds Problem E Easy Problem from Rujia Liu ...

  6. 杭电oj An easy problem

    </pre><h1 style="color: rgb(26, 92, 200);">An easy problem</h1><stron ...

  7. hdu 2055 An easy problem (java)

    问题: 開始尝试用字符做数组元素.可是并没实用. 在推断语句时把a z排出了. An easy problem Time Limit: 1000/1000 MS (Java/Others)    Me ...

  8. Another Easy Problem fzu1753

    Another Easy Problem Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u ...

  9. UESTC 1591 An easy problem A【线段树点更新裸题】

    An easy problem A Time Limit: 2000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others ...

随机推荐

  1. [How To] TrueCrypt使用教學 - 重要資訊的加密保險箱(转)

    我在2013年八月的時候寫了這篇關於TrueCrypt的使用教學,但從去年(2014)五月下旬開始,TrueCrypt的首頁出現了"Using TrueCrypt is not secure ...

  2. how to use boost program options

    From:  http://www.radmangames.com/programming/how-to-use-boost-program_options If it so happens that ...

  3. Android apk签名的两种方法

    编辑推荐:稀土掘金,这是一个针对技术开发者的一个应用,你可以在掘金上获取最新最优质的技术干货,不仅仅是Android知识.前端.后端以至于产品和设计都有涉猎,想成为全栈工程师的朋友不要错过! 为了保证 ...

  4. SPLIT_STR

    CREATE DEFINER=`root`@`%` FUNCTION `vir`.`SPLIT_STR`( x VARCHAR(1000), delim VARCHAR(12), pos INT) R ...

  5. 内存优化总结:ptmalloc、tcmalloc和jemalloc(转)

    转载于:http://www.cnhalo.net/2016/06/13/memory-optimize/ 概述 需求 系统的物理内存是有限的,而对内存的需求是变化的, 程序的动态性越强,内存管理就越 ...

  6. Guava之计时器Stopwatch

    import java.util.concurrent.TimeUnit; import org.junit.Test; import com.google.common.base.Stopwatch ...

  7. MySQL -- Innodb的关闭

    参数innodb_fast_shutdown控制着innodb的关闭模式,有三种取值: 0:     innodb执行slow shutdown,在关闭之前要完成一次full purge和change ...

  8. 【转】iPhone X

    iPhone X 在 CIIA 第一期报告中,我剖析了 iPhone 从诞生以来就存在的,以及后来产生的一些设计问题.昨天在苹果店里玩了一下 iPhone X,发现它不但继承了以往的 iPhone 的 ...

  9. Google file system

    读完了Google file system论文的中文版,记录一下总结,懒得打字,直接上草图:

  10. idea 导入 android项目

    1. 2. 主要是勾选上面选项. next next 导入即可