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?!——题解(配特殊情况图)的更多相关文章

  1. poj2826 An Easy Problem?!【计算几何】

    含[三点坐标计算面积].[判断两线段是否有交点].[求线段交点]模板   An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Tot ...

  2. Poj2826 An Easy Problem

    呵呵哒.WA了无数次,一开始想的办法最终发现都有缺陷.首先需要知道: 1)线段不相交,一定面积为0 2)有一条线段与X轴平行,面积一定为0 3)线段相交,但是能接水的三角形上面线段把下面的线段完全覆盖 ...

  3. poj2826 An Easy Problem?!(计算几何)

    传送门 •题意 两根木块组成一个槽,给定两个木块的两个端点 雨水竖直下落,问槽里能装多少雨水, •思路 找不能收集到雨水的情况 我们令线段较高的点为s点,较低的点为e点 ①两条木块没有交点 ②平行或重 ...

  4. LuoguP7852 「EZEC-9」Yet Another Easy Problem 题解

    Content 给定 \(n,m\),你需要输出一个长度为 \(n\) 的排列,满足该排列进行不超过 \(m\) 次交换操作可以得到的最小的字典序最大. 数据范围:\(T\) 组数据,\(1\leqs ...

  5. An Easy Problem?!(细节题,要把所有情况考虑到)

    http://poj.org/problem?id=2826 An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  6. POJ 2826 An Easy Problem?![线段]

    An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12970   Accepted: 199 ...

  7. POJ 2826 An Easy Problem?!

    An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7837   Accepted: 1145 ...

  8. HDU 5475 An easy problem 线段树

    An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. [POJ] 2453 An Easy Problem [位运算]

    An Easy Problem   Description As we known, data stored in the computers is in binary form. The probl ...

随机推荐

  1. Ruby on Rails Tutorial 第2版 学习笔记

    Ruby on Rails Tutorial 第2版 在线阅读:http://railstutorial-china.org/ 英文版:http://ruby.railstutorial.org/ru ...

  2. Qt-QML-全新导航布局

    哈哈,写了一个全新的导航布局,具体内容还没有完成,现在先把整个布局的屏幕划分分享出来 先看效果图 身下也没有好说的,看代码 /* 作者:张建伟 时间:2018年4月3日 简述:该文件为下显主窗口布局文 ...

  3. tpo-10 C1 How to get photographs exhibited

    第 1 段 1.Listen to a conversation between a student and her Photography professor. 听一段学生和摄影学教授的对话. 第 ...

  4. 对int类型最小值INT_MIN取负值结果不变

    在32位系统中,int类型的最大值是0x7fffffff(即除了最高的1Bit其他31位都为1),而最小值是0x80000000(除了最高1bit,其他31位都为0). 显然,对于最小值求负数是不存在 ...

  5. Linux系统查看系统版本命令

    以下操作在centos系统上实现,有些方式可能只适用centos/redhat版本系统 uname -a |uname -r查看内核版本信息 [root@node1 ~]# uname -a Linu ...

  6. BZOJ 4176 Lucas的数论 莫比乌斯反演+杜教筛

    题意概述:求,n<=10^9,其中d(n)表示n的约数个数. 分析: 首先想要快速计算上面的柿子就要先把d(ij)表示出来,有个神奇的结论: 证明:当且仅当a,b没有相同的质因数的时候我们统计其 ...

  7. POJ 3693 Maximum repetition substring(后缀数组)

    Description The repetition number of a string is defined as the maximum number R such that the strin ...

  8. 【树莓派 Raspberry-Pi 】系统安装及一些必要的配置

    上周六刚收到我的小电脑,被无线设置卡住了,文章并非原创,参考了几个朋友的折腾经历,自己整理下备忘,也希望能帮到和我一样在树莓派方面小白的人,也希望可以和更多有这方面兴趣的朋友共同交流 0. 操作系统下 ...

  9. 一个改变this指向bind的函数,vue源代码

    function bind(fn, ctx) { return function (a) { var l = arguments.length; return l ? l > 1 ? fn.ap ...

  10. Thunder团队第六周 - Scrum会议3

    Scrum会议3 小组名称:Thunder 项目名称:i阅app Scrum Master:李传康 工作照片: 参会成员: 王航:http://www.cnblogs.com/wangh013/ 李传 ...