H - An Easy Problem?!
来源 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?!的更多相关文章
- An easy problem
An easy problem Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- 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, ...
- POJ 2826 An Easy Problem?!
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7837 Accepted: 1145 ...
- hdu 5475 An easy problem(暴力 || 线段树区间单点更新)
http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...
- [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 ...
- 杭电oj An easy problem
</pre><h1 style="color: rgb(26, 92, 200);">An easy problem</h1><stron ...
- hdu 2055 An easy problem (java)
问题: 開始尝试用字符做数组元素.可是并没实用. 在推断语句时把a z排出了. An easy problem Time Limit: 1000/1000 MS (Java/Others) Me ...
- Another Easy Problem fzu1753
Another Easy Problem Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u ...
- UESTC 1591 An easy problem A【线段树点更新裸题】
An easy problem A Time Limit: 2000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others ...
随机推荐
- 奇怪吸引子---LuChen
奇怪吸引子是混沌学的重要组成理论,用于演化过程的终极状态,具有如下特征:终极性.稳定性.吸引性.吸引子是一个数学概念,描写运动的收敛类型.它是指这样的一个集合,当时间趋于无穷大时,在任何一个有界集上出 ...
- 【T05】套接字接口比XTI_TLI更好用
1.用于网络编程的API接口有两种: Berkeley套接字 XTL 2.套接字是加州大学伯克利分校为其Unix操作系统版本开发的,TLI是AT&T(贝尔实验室)为Unix系统V3.0开发的 ...
- MySql之存储过程的使用
一:创建存储过程 1:简单存储过程 CREATE PROCEDURE 存储过程名() BEGIN SQL操作 END; 2:使用参数的存储过程 CREATE PROCEDURE 存储过程名(IN in ...
- Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name
启动apache的时候,报告以下消息提示: Starting httpd: httpd: Could not reliably determine the server's fully qualifi ...
- MyBean通用报表插件介绍
特性: 1.基于MyBean插件平台.可以在任何插件中无缝调用显示. 2.其他窗体中无需引用报表控件.就可以拥有报表的设计预览打印等功能. 3.甚至可以不用带包,制作报表插件,也就是说你可以将RM的报 ...
- Android开发(十三)——全屏滚动与listview
Android全屏滚动使用scrollview,其中有需要采用listview进输出的内容,scrollview与listview冲突. 开始的思维是使用一个Scrollview加上一个ListVie ...
- left join、right join、inner join的区别
left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录inner join(等值连接) 只 ...
- centos 7 配置tomcat开机启动
1. tomcat 需要增加一个pid文件 在tomca/bin 目录下面,增加 setenv.sh 配置,catalina.sh启动的时候会调用,同时配置java内存参数. #add tomcat ...
- 快播王欣发布匿名IM社交软件“马桶MT”
2019年1月14日,快播王欣推出了一款匿名IM社交软件——马桶MT,它的灵感像是来自于美国的匿名分享应用Secret(已关闭). 原快播创始人王欣近日在微博预告了其新公司云歌人工智能推出一款全新社交 ...
- Unity场景渲染相关实现的猜想
如下,很简单的一个场景,一个Panel,二个Cube,一个camera,一个方向光,其中为了避免灯光阴影的影响,关掉阴影,而Panel和二个Cube都是默认的材质,没做修改,我原猜,这三个模型应该都动 ...