poj 2826
太自闭了。。。明明很水的说。。。
有三种为0的情况。一种是有水平,一种是没交点。
第三种有点难想啊。就是下面那个板子被上面的挡住了,,雨水进不去。。。
关键是我翻了翻discuss找到了这种数据,,但是脑子短路了不知道怎么写。。。
我们只要把下面那个端点向上延长!看和上面的板子有没有交点就行了啊!还是看了kuangbin的代码受到的启发。。。
哇我是傻逼啊。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip> using namespace std;
typedef double db;
const db eps = 1e-;
const db pi = acos(-);
int sign(db k){if(k>eps)return ; else if(k<-eps)return -;return ;}
int cmp(db k1,db k2){ return sign(k1-k2);}
struct point{
db x,y;
point operator+(const point &k1)const { return point{k1.x+x,k1.y+y};}
point operator - (const point &k1) const{return (point){x-k1.x,y-k1.y};}
point operator * (db k1) const{return (point){x*k1,y*k1};}
point operator / (db k1) const{return (point){x/k1,y/k1};}
db abs(){ return sqrt(x*x+y*y);}
};
db cross(point k1,point k2){ return k1.x*k2.y-k1.y*k2.x;}
db dot(point k1,point k2){ return k1.x*k2.x+k1.y*k2.y;}
int intersect(db l1,db r1,db l2,db r2){
if (l1>r1) swap(l1,r1); if (l2>r2) swap(l2,r2); return cmp(r1,l2)!=-&&cmp(r2,l1)!=-;
}
int checkSS(point k1,point k2,point k3,point k4){
return intersect(k1.x,k2.x,k3.x,k4.x)&&intersect(k1.y,k2.y,k3.y,k4.y)&&
sign(cross(k3-k1,k4-k1))*sign(cross(k3-k2,k4-k2))<=&&
sign(cross(k1-k3,k2-k3))*sign(cross(k1-k4,k2-k4))<=;
}
point getLL(point k1,point k2,point k3,point k4){
db w1=cross(k1-k3,k4-k3),w2=cross(k4-k3,k2-k3); return (k1*w2+k2*w1)/(w1+w2);
}
point p[];
int t;
int main(){
ios::sync_with_stdio(false);
cout<<fixed<<setprecision();
cin>>t;
while (t--) {
for (int i = ; i <= ; i++) {
cin >> p[i].x >> p[i].y;
}
bool f=;
if(cmp(p[].y,p[].y)==)f=;
if(cmp(p[].y,p[].y)==)f=;
if(!checkSS(p[],p[],p[],p[]))f=;
if(!f){
cout<<0.00<<endl;
continue;
}
point tmp = getLL(p[],p[],p[],p[]);
if(p[].y<p[].y) swap(p[],p[]);
if(p[].y<p[].y) swap(p[],p[]);
if(p[].y>p[].y){//maxy=p[1]
point ano = getLL(p[],tmp,p[],{p[].x-,p[].y});
if (checkSS({p[].x,p[].y},{p[].x,},ano,p[])){
cout<<0.00<<endl;
continue;
}
db ans = cross(p[]-tmp,ano-tmp)/;
ans=abs(ans);
cout<<ans<<endl;
} else{
point ano = getLL(p[],tmp,p[],{p[].x-,p[].y});
if (checkSS({p[].x,p[].y},{p[].x,},ano,p[])){
cout<<0.00<<endl;
continue;
}
db ans = cross(p[]-tmp,ano-tmp)/;
ans=abs(ans);
cout<<ans<<endl;
}
}
}
/**
1
0 0 10 10
0 0 8 9
*/
poj 2826的更多相关文章
- POJ 2826 An Easy Problem? 判断线段相交
POJ 2826 An Easy Problem?! -- 思路来自kuangbin博客 下面三种情况比较特殊,特别是第三种 G++怎么交都是WA,同样的代码C++A了 #include <io ...
- POJ 2826 An Easy Problem?! --计算几何,叉积
题意: 在墙上钉两块木板,问能装多少水.即两条线段所夹的中间开口向上的面积(到短板的水平线截止) 解法: 如图: 先看是否相交,不相交肯定不行,然后就要求出P与A,B / C,D中谁形成的向量是指向上 ...
- POJ 2826 An Easy Problem?!
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7837 Accepted: 1145 ...
- POJ 2826 An Easy Problem?![线段]
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12970 Accepted: 199 ...
- 【POJ 2826】An Easy Problem?!(几何、线段)
两个木条装雨水能装多少. 两线段相交,且不遮盖的情况下才可能装到水. 求出交点,再取两线段的较高端点的较小值h,(h-交点的y)为三角形的高. 三角形的宽即为(h带入两条线段所在直线得到的横坐标的差值 ...
- 简单几何(线段相交) POJ 2826 An Easy Problem?!
题目传送门 题意:两条线段看成两块木板,雨水从上方往下垂直落下,问能接受到的水的体积 分析:恶心的分类讨论题,考虑各种情况,尤其是入口被堵住的情况,我的方法是先判断最高的两个点是否在交点的同一侧,然后 ...
- An Easy Problem?! - POJ 2826(求面积)
题目大意:有两块木板交叉起来接雨水,问最多能接多少. 分析:题目描述很简单,不过有些细节还是需要注意到,如下图几种情况: #include<stdio.h> #include< ...
- POJ 2826 An Easy Problem?! 好的标题
受该两块木板以形成槽的效果.Q槽可容纳雨水多,注意雨爆跌,思想是非常easy,分类讨论是有点差. 1.假定两条线段不相交或平行,然后再装0: 2.有一个平行x轴.连衣裙0. 3.若上面覆盖以下的,装0 ...
- POJ 2826 An Easy Problem?!(线段交点+简单计算)
Description It's raining outside. Farmer Johnson's bull Ben wants some rain to water his flowers. Be ...
随机推荐
- new Random().Next(1, 100); 多线程同时执行结果很高概率相同,
/// <summary> /// new Random().Next(1, 100); 多线程同时执行结果很高概率相同, /// 是用的当前时间为seed,时间相同结果相同 /// // ...
- vue项目启动时将localhost替换成指定ip地址
1.node启动vue项目时地址一般都是http://localhost:8080 2.config->index.js 中的host:‘localhost’换成host:‘你的本机ip’就可以 ...
- edis更新的正确方法
Redis更新的正确方法 https://www.cnblogs.com/westboy/p/8696607.html redis做缓存,怎么更新里面的数据 https://blog.csdn.net ...
- Webdings字体和Wingdings字体对照表
一.Webdings是一个TrueType的dingbat字体,于1997年发表,搭载在其后的Microsoft Windows视窗系统内,大多的字形都没有Unicode的相对字. 使用很简单1.网页 ...
- rpm 打包的时候 不进行strip
http://blog.aka-cool.net/blog/2016/06/01/how-to-disable-strip-in-rpm-build/ https://www.ichenfu.com/ ...
- 天府大讲堂:5G时代的物联网发展趋势与产业变革
摘要:国家973物联网首席科学家,中科院上海微系统与信息技术研究所副所长,无锡物联网产业研究院院长刘海涛教授讲授的5G时代的物联网发展趋势与产业变革意义深刻.作者根据天府大讲堂听讲内容加工整理所得,旨 ...
- 基本够用的php.ini配置文件(CentOS7)
[PHP] engine = On short_open_tag = Off asp_tags = Off precision = output_buffering = zlib.output_com ...
- 恶心github 下载慢
起因 某天看github上面的代码,有点不耐烦,想下载下来再看,但是现在速度慢的可怜 解决思路 相关网站 获取域名相关ip ipaddress.com 这个有好处就是知道网站部署在哪里,如果有vpn的 ...
- windows下telnet命令不好用解决方案;
1.按网上说的windows下打开功能,telnet客户端打钩是必须的: 2.如果还不行,找到telnet.exe:然后把此路径添加到环境变量path下即可: ps:telnet的退出:quit命令:
- 怎么让Windows2012和Windows2008多用户同时远程
具体方法请参照百度经验:http://jingyan.baidu.com/article/cd4c2979f19765756e6e60ec.html.经过实践证明,是没有问题的.