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. 在windows下详解:大端对齐和小端对齐

    计算机的内存最小单位是什么?是BYTE,是字节.一个大于BYTE的数据类型在内存中存放的时候要有先后顺序. 高内存地址放整数的高位,低内存地址放整数的低位,这种方式叫倒着放,术语叫小端对齐.电脑X86 ...

  2. vi 方向键和Backspace键失效问题的解决方法

    安装的ubuntu默认的编辑器是vi,遇到了两个问题: ① insert模式下,按方向键将产生A.B.C.D等字符,解决方案: :set nocompatible ② insert模式下Backspa ...

  3. JXLS 2.4.0系列教程(二)——循环导出一个链表的数据

    请务必先看上一篇文章,本文在上一篇文章的代码基础上修改而成. JXLS 2.4.0系列教程(一)--最简单的模板导出 上一篇文章我们介绍了JXLS和模板导出最简单的应用,现在我们要更进一步,介绍在模板 ...

  4. 一步一步从原理跟我学邮件收取及发送 4.不同平台下的socket

    既然是面向程序员的文章那当然不能只说说原理,一定要有实际动手的操作.    其实作为我个人的经历来说,对于网络编程,这是最重要的一章! 作为一位混迹业内近20年的快退休的程序员,我学习过很多的开发语言 ...

  5. [国嵌笔记][020][ARM家族大检阅]

    ARM芯片:2440(arm9) 6410(arm11) 210(cortex-A8) ARM核:arm9(arm-v4) arm11(arm-v6) cortex-A8(arm-v7) 指令架构:a ...

  6. 关于STM32驱动DS1302实时时钟的一点思考

    之前用51驱动过DS1302,没用多久就输出了正确的时间.当时以为这块芯片其实没啥,很简单.但是现在用STM32做项目,用到同样的芯片,以为这有何难,只要把那个程序拿过来复制黏贴改一下IO设置不就行了 ...

  7. 微信公众号中ip白名单用谁的ip

    https://segmentfault.com/q/1010000010201211 白名单怎么说 我该填写谁的 我的ip地址每天都变化的 服务器ip啊,为了防止未授权的代码盗用你的权限.写你ip是 ...

  8. PHP条件语句if的使用

    方法/步骤 if(条件){是否执行的代码...}:这样的用法常用于判断单一条件,当然,可以可以用逻辑符号将多个条件组合成同一条件. if else语句:如果条件不成立,就会执行else后面{}里的代码 ...

  9. JavaScript之BST

    自己尝试用js实现了数据结构的二叉查找树. // node function Node(data) { this.data = data; this.lc = null; this.rc = null ...

  10. SQLite学习手册(实例代码<一>)

    一.获取表的Schema信息:       1). 动态创建表.     2). 根据sqlite3提供的API,获取表字段的信息,如字段数量以及每个字段的类型.     3). 删除该表.     ...