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 ...
随机推荐
- 【Little Demo】从简单的Tab标签到Tab图片切换
Tab标签切换效果是比较流行的一种网站页面布局,视觉表现为美观大方,通过标签展示内容.目前在各大网站都有存在这种效果.例如:淘宝的黄金位置使用Tab标签切换效果,网易新闻等. 1.简单的 Tab 标签 ...
- task_payment_byonlinedown
CREATE DEFINER=`root`@`%` PROCEDURE `vir`.`task_payment_byonlinedown`()begin declare _mobile varchar ...
- Python 读取WAV文件并绘制波形图
aa Python 读取WAV文件并绘制波形图 ffmpeg -i test_pcm_mulaw.wav -f wav -codec:a pcm_s16le -ar 8000 -ac 1 out.wa ...
- C语言100个经典的算法
C语言的学习要从基础開始.这里是100个经典的算法-1C语言的学习要从基础開始,这里是100个经典的算法 题目:古典问题:有一对兔子,从出生后第3个月起每一个月都生一对兔子.小兔 子长到第三个月后每一 ...
- oracle排序后的第一条记录
该查寻语句没有经过任何的优化,因为oracle没有SQL的TOP关键字,但是有一个ROWNUM的列,因此,可以通过ROWNUM来进行查询.oracle的关于rownum的参考手册里面提到了 分析 ...
- SQL 中的多条件查询
在应用程序开发中,多条件查询是个经常遇到的情况,最简单最麻烦的方法是把所有的可能情况都考虑到,但是无疑是繁琐的,而且很容易漏掉可能的情形,下面是SQL语句实现多条件查询的情况 select * fro ...
- Git教程学习(三)
主要命令: $ git checkout -- readme.txt #使用暂存区或版本库中最新的版本替换工作区版本 $ git reset HEAD readme.txt # 撤消指定文件的add操 ...
- request.GetResponse()超时的解决办法
var request = (HttpWebRequest)WebRequest.Create(url); request.Timeout = Timeout.Infinite; request.Ke ...
- 运行第一个Docker容器-Docker for Web Developers(1)
1. Docker介绍 Docker由dotCloud公司发起的一个内部项目,后来Docker火了,dotCloud公司改名为Docker了: Docker使用了Go语言开发,基于 Linux 内核的 ...
- 《软件测试自动化之道》读书笔记 之 SQL 存储过程测试
<软件测试自动化之道>读书笔记 之 SQL 存储过程测试 2014-09-28 待测程序测试程序 创建测试用例以及测试结果存储 执行T-SQL脚本 使用BCP工具导入测试用例数据 ...