An Easy Problem?!
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 12970   Accepted: 1995

Description

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, x1y1x2y2x3y3x4y4. (x1y1), (x2y2) are the endpoints of one board, and (x3y3), (x4y4) 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

Source

POJ Monthly--2006.04.28, Dagger@PKU_RPWT

哈哈哈A掉了 过年啦!!!
[2017-01-28]
好了好了大年初一补题解:
本题就是特殊情况特别多,参考kuangbin
线段不相交,结果为0.
有一条线段平行于x轴结果也为0;
 
我最后求面积的方法和别人不太一样,我是从三角形上面两个点中低的做水平线,与另一条交点再用叉积
还有就是好多人说最后答案要加上eps避免-0.00,然而我不加也可以
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
const double eps=1e-;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
inline int sgn(double x){
if(abs(x)<eps) return ;
else return x<?-:;
}
struct Vector{
double x,y;
Vector(double a=,double b=):x(a),y(b){}
bool operator <(const Vector &a)const{
return x<a.x||(x==a.x&&y<a.y);
}
void print(){
printf("%lf %lf\n",x,y);
}
};
typedef Vector Point;
Vector operator +(Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);}
Vector operator -(Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}
Vector operator *(Vector a,double b){return Vector(a.x*b,a.y*b);}
Vector operator /(Vector a,double b){return Vector(a.x/b,a.y/b);}
bool operator ==(Vector a,Vector b){return sgn(a.x-b.x)==&&sgn(a.y-b.y)==;} double Cross(Vector a,Vector b){
return a.x*b.y-a.y*b.x;
}
double Dot(Vector a,Vector b){
return a.x*b.x+a.y*b.y;
}
double DisPP(Point a,Point b){
Point t=a-b;
return sqrt(t.x*t.x+t.y*t.y);
}
double Len(Vector a){return sqrt(Dot(a,a));}
struct Line{
Point s,t;
Line(){}
Line(Point p,Point v):s(p),t(v){}
}; bool isLSI(Line l1,Line l2){
Vector v=l1.t-l1.s,u=l2.s-l1.s,w=l2.t-l1.s;
return sgn(Cross(v,u))!=sgn(Cross(v,w));
}
bool isSSI(Line l1,Line l2){
return isLSI(l1,l2)&&isLSI(l2,l1);
}
Point LI(Line a,Line b){
Vector v=a.s-b.s,v1=a.t-a.s,v2=b.t-b.s;
double t=Cross(v2,v)/Cross(v1,v2);
return a.s+v1*t;
} double DisTL(Point p,Point a,Point b){
Vector v1=b-a,v2=p-a;
return abs(Cross(v1,v2)/Len(v1));
} int n;
double x,y,x2,y2;
Line l1,l2;
double solve(){
if(sgn(l1.s.y-l1.t.y)==||sgn(l2.s.y-l2.t.y)==) return ;
if(sgn(Cross(l1.t-l1.s,l2.t-l2.s))==) return ;
if(!isSSI(l1,l2)) return ; if(l1.s.y>l1.t.y) swap(l1.s,l1.t);
if(l2.s.y>l2.t.y) swap(l2.s,l2.t); if(isSSI(Line(l1.t,Point(l1.t.x,)),l2)) return ;
if(isSSI(Line(l2.t,Point(l2.t.x,)),l1)) return ;
//puts("hi");
Point p=LI(l1,l2),a=l1.t,b=l2.t;//p.print();
if(a.y>b.y) swap(a,b),swap(l1,l2); Line t(a,Point(,a.y));
Point c=LI(t,l2);//c.print();
return abs(Cross(a-p,c-p))/;
}
int main(int argc, const char * argv[]) {
int T=read();
while(T--){
scanf("%lf%lf%lf%lf",&x,&y,&x2,&y2);
l1=Line(Point(x,y),Point(x2,y2));
scanf("%lf%lf%lf%lf",&x,&y,&x2,&y2);
l2=Line(Point(x,y),Point(x2,y2));
printf("%.2f\n",solve()+eps);
}
return ;
}

POJ 2826 An Easy Problem?![线段]的更多相关文章

  1. POJ 2826 An Easy Problem? 判断线段相交

    POJ 2826 An Easy Problem?! -- 思路来自kuangbin博客 下面三种情况比较特殊,特别是第三种 G++怎么交都是WA,同样的代码C++A了 #include <io ...

  2. POJ 2826 An Easy Problem?!

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

  3. POJ 2826 An Easy Problem?!(线段交点+简单计算)

    Description It's raining outside. Farmer Johnson's bull Ben wants some rain to water his flowers. Be ...

  4. 简单几何(线段相交) POJ 2826 An Easy Problem?!

    题目传送门 题意:两条线段看成两块木板,雨水从上方往下垂直落下,问能接受到的水的体积 分析:恶心的分类讨论题,考虑各种情况,尤其是入口被堵住的情况,我的方法是先判断最高的两个点是否在交点的同一侧,然后 ...

  5. POJ 2826 An Easy Problem?! 好的标题

    受该两块木板以形成槽的效果.Q槽可容纳雨水多,注意雨爆跌,思想是非常easy,分类讨论是有点差. 1.假定两条线段不相交或平行,然后再装0: 2.有一个平行x轴.连衣裙0. 3.若上面覆盖以下的,装0 ...

  6. POJ 2826 An Easy Problem?! --计算几何,叉积

    题意: 在墙上钉两块木板,问能装多少水.即两条线段所夹的中间开口向上的面积(到短板的水平线截止) 解法: 如图: 先看是否相交,不相交肯定不行,然后就要求出P与A,B / C,D中谁形成的向量是指向上 ...

  7. POJ 2826 An Easy Problem!(简单数论)

    Description Have you heard the fact "The base of every normal number system is 10" ? Of co ...

  8. POJ 1152 An Easy Problem! (取模运算性质)

    题目链接:POJ 1152 An Easy Problem! 题意:求一个N进制的数R.保证R能被(N-1)整除时最小的N. 第一反应是暴力.N的大小0到62.发现当中将N进制话成10进制时,数据会溢 ...

  9. HDU 5475 An easy problem 线段树

    An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

随机推荐

  1. NYOJ 2356 哈希计划(模拟)

    题目链接: http://acm.nyist.me/JudgeOnline/problem.php?id=2356 题目描述 众所周知,LLM的算法之所以菜,就是因为成天打游戏,最近LLM突然想玩&l ...

  2. AD转换

    一.AD转换的概念  AD转换的功能是把模拟量电压转换为数字量电压.DA转换的功能正好相反,就是讲数字量转换位模拟量. 二.芯片PCF8591介绍 PCF8591是一个单片集成.单独供电.低功耗.8- ...

  3. github网站介绍、并使用git命令管理github(详细描述)

    本章学习: 1)熟悉github网站 2)通过git命令远程管理github, 3)git命令使用ssh key密钥无需输入账号密码 1.首先我们来熟悉github网站 1.1 注册github 登录 ...

  4. 学习总结:libevent--简单入门

    libevent--简单入门 一.简介 libevent是一个c语言写的事件驱动库,轻量级,专注于网络,跨平台特性好,支持多种 I/O 多路复用.支持I/O,定时器和信号等事件,允许设置注册事件优先级 ...

  5. Git学习记录--git仓库

    Git是一款强大的版本控制工具,与svn相比git的分布式提交,本地仓库等在使用时确实比较方便.当然两者之间各有优劣,我在这里不多做比较.由于之前少有接触git,只是零星大致地了解一点,所以找时间系统 ...

  6. Source Insight、Xshell(putty)、Xftp

    body, table{font-family: 微软雅黑} table{border-collapse: collapse; border: solid gray; border-width: 2p ...

  7. scss 初学笔记 三 继承

    //继承 .btn{ padding: 4px 10px; font-size: 14px; } .primary{ background:red; @extend .btn; } //%placeh ...

  8. 8_python连接数据库

    如何用python操作数据库? -- 导入pymysql                    -- import pymysql -- 创建连接                          - ...

  9. junit测试延伸--方法的重复测试

    在实际编码测试中,我们有的时候需要对一个方法进行多次测试,那么怎么办呢?这个问题和测试套件解决的方案一样,我们总不能不停的去右键run as,那怎么办呢?还好伟大的junit帮我们想到了. OK,现在 ...

  10. Tomcat 的设计模式分析

    最近在研究tomcat,手上有一份尚硅谷的tomcat设计模式的资料,翻开看了看个人觉得写得还是很好的.设计模式一般都是在有一定的代理积累之后才能用到的相关的这种解决方案.常用的一共有23种设计模式, ...