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. android弹力效果菜单、组件化项目、电影票选座控件的源码

    Android精选源码 android启动扫一扫和收付款的小部件源码 android弹力效果的抽屉菜单源码 对RecyclerView Item做动画 源码 android类似QQ空间,微信朋友圈,微 ...

  2. 解决指向iframe的target失效

    今天遇到一个bug. 主页面中点击左侧导航栏[某]项后,右侧的iframe页面加载到了新窗口.之后,所有选项的iframe加载都异常. 检查<a>标签target="main&q ...

  3. .29-浅析webpack源码之Resolver.prototype.resolve

    在上一节中,最后返回了一个resolver,本质上就是一个Resolver对象: resolver = new Resolver(fileSystem); 这个对象的构造函数非常简单,只是简单的继承了 ...

  4. js数组操作记录

    一 .splice() 方法向/从数组中添加/删除项目,然后返回被删除的项目. arrayObject.splice(index,howmany,item1,.....,itemX) 参数 描述 in ...

  5. Maven打包时去掉项目版本号

    Maven打包后,jar或war文件名里带有版本号信息,如projectname0.0.1-SNAPSHOT.jar等,怎么去掉呢? 解决办法: 打开项目pom.xml文件,在<build> ...

  6. python爬虫知乎

    在之前写过一篇使用python爬虫爬取电影天堂资源的博客,重点是如何解析页面和提高爬虫的效率.由于电影天堂上的资源获取权限是所有人都一样的,所以不需要进行登录验证操作,写完那篇文章后又花了些时间研究了 ...

  7. Linuxc - 标准输入流、标准输出流、标准错误流

    输入流stdin默认是键盘,输出流stdout默认是显示器,错误流stderr #include <stdio.h> int main() { printf("请输入选择的数字: ...

  8. JavaScript Math(数学对象)

    Math(数学对象) Math 算术函数和常量 Math.abs( ) 计算绝对值 Math.acos( ) 计算反余弦值 Math.asin( ) 计算反正弦值 Math.atan( ) 计算反正切 ...

  9. mysql explain用法和结果的含义

    转自:http://blog.chinaunix.net/uid-540802-id-3419311.html explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择 ...

  10. MySQLdb 部署

    1.windows 下载后,直接安装即可 http://www.jb51.net/softs/73369.html#download 双击安装 MySQL-python-1.2.3.win32-py2 ...