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 ...
随机推荐
- 微信公众号基础02_获取accessToken和用户信息
上一篇分享了搭建微信公众号server,本文分享一下假设获取access_Token和用户信息.工具还是新浪云SAE 1.获取access_Token 相见开发文档:https://mp.weixin ...
- Tomcat 七 HTTP 连接器
摘要 本文尝试翻译Tomcat官方文档Apache Tomcat 7连接器,不足之处敬请指正.该文先介绍了Tomcat7 HTTP连接器的属性,包括:公共属性.标准实现.Java TCP套接字属性.B ...
- Asp.Net MVC4中的全局过滤器
可以对整个项目进行全局监控. 新建一个MVC4项目,可以在global.asax文件中看到如下代码: FilterConfig.RegisterGlobalFilters(GlobalFilters ...
- java解惑--摘要
(1)下面是一个试图解决上述问题的程序,它会打印出什么呢?public class Change{public static void main(String args[]){System.out.p ...
- SNF快速开发平台--多组织+多平台+多系统处理方案
多组织架构的集团要看组织的组成形式: 1.如果每个组织都是独立法人,这个相对来说简单一些,组织之间的关联交易跟集团外部客户交易没什么本质区别, 各个公司都是独立核算,正常的应收应付都需要开发票,各自出 ...
- 当 Visual Studio 扩展遇到错误时
我是遇到了 Github 扩展经常在 Visual Studio 启动时报错,找了一下可以尝试以下方法: 首先卸载插件 然后删除 %LocalAppData%\Microsoft\VisualStud ...
- [ci]jenkins-slave-ssh docker容器化-自动注入key
jenkins server 再启动slave时候,动态的注入sshkey 只要slave有ssh+jdk即可.无需事先预置用户名密码给slave. 配置 inject ssh key 配置项目 执行 ...
- VirtualBox 端口转发 SSH
在服务器上安装VirtualBox并配置转发: VirtualBox网络连接方式,选择默认的NAT连接方式. 在下面有个 “端口转发” 按钮,点击配置主机到虚拟机的端口映射. ref: http:// ...
- 施工测量中Cad一些非常有用的插件
经常会遇到坐标在cad中批量展点.从cad中批量保存坐标点.导入cad中的坐标怎么才能有点号,怎么快速标注cad里的坐标点··· ··· 这一切都是可以程序化的,cad是可以二次开发的,我经常用易语言 ...
- pip离线安装软件包
1. 首先一台主机上安装所有python包,然后运行如下命令下载依赖包: pip freeze > requirements pip download -r requirements 当然可以在 ...