POJ2826:An Easy Problem?!——题解(配特殊情况图)
http://poj.org/problem?id=2826
题目大意:给两条线,让它接竖直下的雨,问其能装多少横截面积的雨。
————————————————————————————
水题,看题目即可知道。
但是细节是真的多……不过好在两次AC应该没算被坑的很惨(全程没查题解)。
推荐交之前看一下讨论版的数据,方便一次AC(我第一次就是作死直接交了结果我自己都想好的情况忘了写了……)
相信看到这篇题解的人都看过题了,那么先说细节:
1.C++提交(G++不知道为什么WA了……)
2.精度
3.特殊情况,看看下面哪种情况你没有考虑到(以下都是没法装水的情况):






还有一种能够接水的情况:

将上面考虑完了,应该就差不多了。
那么说一下正解:
1.ko掉所有平行情况。(图3)
2.ko掉所有不相交情况。(图6)
3.ko掉所有斜率为0的情况。(图5)
4.上述两种情况完成后,求交点。
5.发现图1和图7情况只存在于斜率同号的情况下,特判之。
6.图2和图4一并解决:从交点处画一条平行于x的线,如果在该线上方的点的个数不为2,则不能接水。
7.上述情况讨论完后一定能接水,从6中获得的两个点取y值最小的点画一条平行于x的线,则围成的面积即为所求
总结:
线关系和线交点的题,细节较多,代码实现较长较繁琐,不推荐读下面代码。
#include<cstdio>
#include<queue>
#include<cctype>
#include<cstring>
#include<stack>
#include<cmath>
#include<algorithm>
using namespace std;
typedef double dl;
const dl eps=1e-;
const dl INF=;
struct point{
dl x;
dl y;
}p[];
inline point getmag(point a,point b){
point s;
s.x=b.x-a.x;s.y=b.y-a.y;
return s;
}
inline dl multiX(point a,point b){
return a.x*b.y-b.x*a.y;
}
inline dl multiP(point a,point b){
return a.x*b.x+b.y*a.y;
}
inline bool parallel_mag(point a,point b){
if(fabs(a.x*b.y-a.y*b.x)<eps)return ;
return ;
}
inline bool check(point a,point b,point c,point d){
if(multiX(getmag(c,d),getmag(c,a))*multiX(getmag(c,d),getmag(c,b))>eps)return ;
if(multiX(getmag(a,b),getmag(a,c))*multiX(getmag(a,b),getmag(a,d))>eps)return ;
return ;
}
inline point intersection(point a,point b,point c,point d){
point s;
dl a1=a.y-b.y,b1=b.x-a.x,c1=a.x*b.y-b.x*a.y;
dl a2=c.y-d.y,b2=d.x-c.x,c2=c.x*d.y-d.x*c.y;
s.x=(c1*b2-c2*b1)/(a2*b1-a1*b2);
s.y=(a2*c1-a1*c2)/(a1*b2-a2*b1);
return s;
}
inline dl slope(point a,point b){
if(fabs(a.x-b.x)<eps)return INF;
return (a.y-b.y)/(a.x-b.x);
}
inline bool deng(point a,point b){
if(fabs(a.x-b.x)<eps&&fabs(a.y-b.y)<eps)return ;
return ;
}
inline bool pan(point s){
dl k1=slope(p[],p[]);
dl k2=slope(p[],p[]);
if(fabs(k1)<eps||fabs(k2)<eps)return ;
if(k1>eps&&k2>eps){
if(k2-k1>eps){
if(-eps<p[].x-p[].x)return ;
}else{
if(-eps<p[].x-p[].x)return ;
}
}
if(k1<-eps&&k2<-eps){
if(k1<k2){
if(p[].x-p[].x>-eps)return ;
}else{
if(p[].x-p[].x>-eps)return ;
}
return ;
}
int ok=;
for(int i=;i<=;i++){
if(p[i].y-s.y>eps){
ok++;
}
}
if(ok!=)return ;
return ;
}
dl area(){
if(parallel_mag(getmag(p[],p[]),getmag(p[],p[])))return ;
if(!check(p[],p[],p[],p[]))return ;
point s=intersection(p[],p[],p[],p[]);
if(!pan(s))return ;
int s1=,s2=;
for(int i=;i<=;i++){
if(p[i].y-s.y>eps){
if(!s1)s1=i;
else s2=i;
}
}
point ns,nss,n1,n2;
if(eps<p[s2].y-p[s1].y){
ns.x=p[s1].x;ns.y=p[s1].y;
}else{
ns.x=p[s2].x;ns.y=p[s2].y;
}
nss.x=INF;nss.y=ns.y;
n1=intersection(p[],p[],ns,nss);
n2=intersection(p[],p[],ns,nss);
return fabs(multiX(getmag(s,n1),getmag(s,n2)))/;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
for(int i=;i<=;i++)scanf("%lf%lf",&p[i].x,&p[i].y);
if(p[].x>p[].x)swap(p[],p[]);
if(p[].x>p[].x)swap(p[],p[]);
printf("%.2f\n",area());
}
return ;
}
POJ2826:An Easy Problem?!——题解(配特殊情况图)的更多相关文章
- poj2826 An Easy Problem?!【计算几何】
含[三点坐标计算面积].[判断两线段是否有交点].[求线段交点]模板 An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Tot ...
- Poj2826 An Easy Problem
呵呵哒.WA了无数次,一开始想的办法最终发现都有缺陷.首先需要知道: 1)线段不相交,一定面积为0 2)有一条线段与X轴平行,面积一定为0 3)线段相交,但是能接水的三角形上面线段把下面的线段完全覆盖 ...
- poj2826 An Easy Problem?!(计算几何)
传送门 •题意 两根木块组成一个槽,给定两个木块的两个端点 雨水竖直下落,问槽里能装多少雨水, •思路 找不能收集到雨水的情况 我们令线段较高的点为s点,较低的点为e点 ①两条木块没有交点 ②平行或重 ...
- LuoguP7852 「EZEC-9」Yet Another Easy Problem 题解
Content 给定 \(n,m\),你需要输出一个长度为 \(n\) 的排列,满足该排列进行不超过 \(m\) 次交换操作可以得到的最小的字典序最大. 数据范围:\(T\) 组数据,\(1\leqs ...
- An Easy Problem?!(细节题,要把所有情况考虑到)
http://poj.org/problem?id=2826 An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- POJ 2826 An Easy Problem?![线段]
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12970 Accepted: 199 ...
- POJ 2826 An Easy Problem?!
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7837 Accepted: 1145 ...
- HDU 5475 An easy problem 线段树
An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- [POJ] 2453 An Easy Problem [位运算]
An Easy Problem Description As we known, data stored in the computers is in binary form. The probl ...
随机推荐
- CakePHP中回调函数的使用
我们知道模型主要是用来处理数据的,有时我们想在模型操作之前或之后做一些额外逻辑处理,这时候就可以使用回调函数. 回调函数有很多种,beforeFind,afterFind,beforeValidate ...
- centos7 的防火墙命令调整了
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙.firewall:systemctl start firewalld.service#启动firewalls ...
- 一个只有十行的精简MVVM框架
本文来自网易云社区. 前言 MVVM模式相信做前端的人都不陌生,去网上搜MVVM,会出现一大堆关于MVVM模式的博文,但是这些博文大多都只是用图片和文字来进行抽象的概念讲解,对于刚接触MVVM模式的新 ...
- 安装MySQLdb模块遭遇"fatal error: my_config.h: No such file or directory"的处理
Issue I encountered an error when I run the python script which need to import the module of & ...
- Qt-网络与通信-UDP网络通讯
用户数据报协议是一种简单的轻量级.不可靠.面向数据.无连接的传出层协议,可以应用于在可靠性不是十分重要的场合,如短消息,广播信息等. 例如一下场合 网络数据大多为短消息 拥有大量客户端 对数据安全性无 ...
- 提权基础-----mysql-udf提权
1.总结关于udf提权方法 通过弱口令,爆破,网站配置文件等方式得到mysql数据库帐号密码,---还要能外连 (1).将udf.dll代码的16进制数声明给my_udf_a变量 set @my_ud ...
- Linux命令应用大词典-第39章 网络安全
39.1 rtacct:网络统计工具 39.2 nmap:报告远程主机特征 39.3 tcpdump:实现网络数据采集分析 39.4 iptstate:显示IP表状态表条目 39.5 nstat:监控 ...
- python终极篇 ---django 模板系统
模板系统 . MV ...
- python常用命令—查看模块所在位置
环境:ipython3 交互式解释器 语法: import 模块名 模块名.__file__ 功能: 查看模块的所在位置 例:
- Map Reduce Application(Partitioninig/Binning)
Map Reduce Application(Partitioninig/Group data by a defined key) Assuming we want to group data by ...