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 ...
随机推荐
- iOS:使用NSRegularExpression正则去掉一串字符串中所有的特殊字符和标点
一.介绍 在开发中,有时我们需要对一串字符串做特殊的处理后再使用,例如判断是不是特殊字符.去掉所有的特殊字符等.做处理的方法有很多,最简单的就是for循环遍历一个个的比较处理,最好用的应该是使用正则表 ...
- vs2010编译错误(报错:LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏)
报错:LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 1> 这段时间忙于看文献,没用过VS了. 今天用着用着就报错了: LINK : fat ...
- CentOS7 下 keepalived 的安装和配置
安装前准备:yum -y install gcc gcc-c++ autoconf automake make yum -y install zlib zlib-devel openssl opens ...
- 使用lightProbe来模拟动态物体的照明shader
VertexLit path中读取lightProbe烘焙信息: Shader "VertexLitProbe" { Properties { _MainTex ("Ba ...
- shell while内获取外部变量内容
一.问题 问题很简单,看下面一段tmp.sh代码: #!/bin/sh x="this is the initial value of x" cat /tmp/tmp | whil ...
- jQuery实现表格行上移下移和置顶
jQuery实现表格行上移下移和置顶 我们在操作列表数据的时候,需要将数据行排列顺序进行调整,如上移和下移行,将行数据置顶等,这些操作都可以在前端通过点击按钮来完成,并且伴随着简单的动态效果,轻松实现 ...
- 【Android】详解Android Service
目录结构: contents structure [+] Service简单概述 Service在清单文件中的声明 Service启动服务 Service绑定服务 扩展Binder类 使用Messen ...
- Linux查看CPU和内存的配置信息
CPU配置信息:frank@ubuntu:~/test/python$ cat /proc/cpuinfo processor : #系统中逻辑处理核的编号 vendor_id : GenuineIn ...
- ESXi创建磁盘命令
[root@esx421 SAN]# vmkfstools -d thick -a lsilogic -c 10G lun00.vmdk Incorrect disk option "thi ...
- java中的数据加密5 数字证书
数字证书 A用私钥加密了,那么B接受到消息后,用A提供的公钥解密:那么现在有个讨厌的C,他把消息拦截了,然后用自己的私钥加密,同时把自己的公钥发给B,并告诉B,那是A的公钥,结果....,这时候就需要 ...