POJ 2826 An Easy Problem?![线段]
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 12970 | Accepted: 1995 |
Description

Your mission is to calculate how much rain these two boards can collect.
Input
Each test case consists of 8 integers not exceeding 10,000 by absolute value, x1, y1, x2, y2, x3, y3, x4, y4. (x1, y1), (x2, y2) are the endpoints of one board, and (x3, y3), (x4, y4) are the endpoints of the other one.
Output
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

#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?![线段]的更多相关文章
- POJ 2826 An Easy Problem? 判断线段相交
POJ 2826 An Easy Problem?! -- 思路来自kuangbin博客 下面三种情况比较特殊,特别是第三种 G++怎么交都是WA,同样的代码C++A了 #include <io ...
- POJ 2826 An Easy Problem?!
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7837 Accepted: 1145 ...
- POJ 2826 An Easy Problem?!(线段交点+简单计算)
Description It's raining outside. Farmer Johnson's bull Ben wants some rain to water his flowers. Be ...
- 简单几何(线段相交) POJ 2826 An Easy Problem?!
题目传送门 题意:两条线段看成两块木板,雨水从上方往下垂直落下,问能接受到的水的体积 分析:恶心的分类讨论题,考虑各种情况,尤其是入口被堵住的情况,我的方法是先判断最高的两个点是否在交点的同一侧,然后 ...
- POJ 2826 An Easy Problem?! 好的标题
受该两块木板以形成槽的效果.Q槽可容纳雨水多,注意雨爆跌,思想是非常easy,分类讨论是有点差. 1.假定两条线段不相交或平行,然后再装0: 2.有一个平行x轴.连衣裙0. 3.若上面覆盖以下的,装0 ...
- POJ 2826 An Easy Problem?! --计算几何,叉积
题意: 在墙上钉两块木板,问能装多少水.即两条线段所夹的中间开口向上的面积(到短板的水平线截止) 解法: 如图: 先看是否相交,不相交肯定不行,然后就要求出P与A,B / C,D中谁形成的向量是指向上 ...
- POJ 2826 An Easy Problem!(简单数论)
Description Have you heard the fact "The base of every normal number system is 10" ? Of co ...
- POJ 1152 An Easy Problem! (取模运算性质)
题目链接:POJ 1152 An Easy Problem! 题意:求一个N进制的数R.保证R能被(N-1)整除时最小的N. 第一反应是暴力.N的大小0到62.发现当中将N进制话成10进制时,数据会溢 ...
- HDU 5475 An easy problem 线段树
An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
随机推荐
- 【JAVA】hashcode() & equals()
平时使用map时都是用JAVA原生的类型,所以很少关注到hashcode()和equals()的方法的内部实现.近期实现一个小工具,涉及到自己写的类的查找比对,又再次重温了相关的知识. 上简单示例代码 ...
- MVC学习笔记(分享)
一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于SpringMVC的配置 <!--conf ...
- word文档自动生成方法
创建word文档需要几个接口类,常用application,document,documents,selection等.但word的功能复杂,要认识到每一个类的功能是不可能的.常用的方法是在word的 ...
- 在Sql Server Intergration Service中设置Catalog下所部署所有项目的参数值
在Sql Server 2012开始,微软给SSIS添加了Project Model这种新的项目类型,与之对应的是在Sql Server数据库引擎中引入了Intergration Services C ...
- UE4 保存为bitmap
TArray<FColor> colorData; colorData.Init(FColor(0, 0, 255, 255), 1920 * 1080); for (int ...
- JavaScript八张思维导图—基本语句
JS基本概念 JS操作符 JS基本语句 JS数组用法 Date用法 JS字符串用法 JS编程风格 JS编程实践 不知不觉做前端已经五年多了,无论是从最初的jQuery还是现在火热的Angular,Vu ...
- Java客户端API
添加依赖 <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookee ...
- maven项目 在eclipse,InteliJ IDEA中的一些问题
转载请注明出处,谢谢! 不论我们用什么ide来编辑我们的代码,最终的产品都会脱离ide来运行:正如燕飞离了巢,正如你离开了家,不期然就会运转出现问题. - 单强 2018年1月26日11:53 大家是 ...
- 织梦CMS提示DedeTag Engine Create File False错误的解决办法总结
今天帮客户升级站点,遇到了一个老问题,生成栏目的时候提示"DedeTag Engine Create File False",突然发觉这个问题竟然在以前做站的时候困扰过我多次,于是 ...
- LNMP一键安装包
http://www.aliweihu.com/333.html LNMP一键安装包是什么? LNMP一键安装包是一个用Linux Shell编写的可以为CentOS/RadHat.Debian/Ub ...