题目大意:有两块木板交叉起来接雨水,问最多能接多少。
 
分析:题目描述很简单,不过有些细节还是需要注意到,如下图几种情况:
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std; const int MAXN = ;
const double oo = 1e4+;
const double EPS = 1e-; int sign(double val)
{
if(val > EPS)return ;
if(fabs(val) < EPS)return ;
return -;
} struct Point
{
double x, y;
Point(double x=, double y=):x(x), y(y){}
Point operator - (const Point &tmp) const{
return Point(x-tmp.x, y-tmp.y);
}
double operator ^(const Point &tmp) const{
return x*tmp.y - y*tmp.x;
}
bool operator == (const Point &tmp) const{
return fabs(x-tmp.x) < EPS && fabs(y-tmp.y) < EPS;
}
double operator *(const Point &tmp) const{
return x*tmp.x + y*tmp.y;
}
};
struct Segment
{
Point s, e;
double a, b, c;///ax + by = c
Segment(Point s=, Point e=):s(s), e(e){
a = s.y - e.y;
b = e.x - s.x;
c = e.x*s.y - s.x*e.y;
}
bool Inter(const Segment &t)const{
int v1 = sign((s-e)^(t.s-e));
int v2 = sign((s-e)^(t.e-e)); if(!v1 && !v2)return false;///共线 if(!v1 && t.s.x >= min(s.x, e.x) && t.s.x <= max(s.x, e.x)
&& t.s.y >= min(s.y, e.y) && t.s.y <= max(s.y, e.y)
|| !v2 && t.e.x >= min(s.x, e.x) && t.e.x <= max(s.x, e.x)
&& t.e.y >= min(s.y, e.y) && t.e.y <= max(s.y, e.y)
|| v1 * v2 == -)return true; return false;
}
Point CrossNode(const Segment &t) const{
Point ans;
ans.x = (c*t.b-t.c*b)/(a*t.b-t.a*b);
ans.y = (c*t.a-t.c*a)/(b*t.a-t.b*a); return ans;
}
};
double Dist(Point a, Point b)
{
return sqrt((a-b) * (a-b));
}
double Find(Point crs, Point p[], int N)
{
double sum = ; for(int i=; i<N; i++)
for(int j=i+; j<N; j++)
{
int k = sign((p[i]-crs)^(p[j]-crs)); if(p[i] == p[j])continue; if(crs.x>=min(p[i].x, p[j].x) && crs.x<=max(p[i].x, p[j].x)
|| crs.x>=p[i].x && crs.x>=p[j].x && (k>&&(p[i].x-p[j].x>EPS) || k<&&(p[j].x-p[i].x>EPS))
|| crs.x<=p[i].x && crs.x<=p[j].x && (k<&&(p[j].x-p[i].x>EPS) || k>&&(p[i].x-p[j].x>EPS)))
if(p[i].y-crs.y > EPS && p[j].y-crs.y > EPS)
{
Point A = p[i].y < p[j].y ? p[i] : p[j];
Point B = (A == p[i] ? p[j] : p[i]);
Segment t1(Point(-oo, A.y), Point(oo, A.y));
Segment t2(crs, B); B = t1.CrossNode(t2); double La = Dist(A, B);
double Lb = Dist(A, crs);
double Lc = Dist(B, crs);
double p = (La+Lb+Lc) / ; sum += sqrt(p*(p-La)*(p-Lb)*(p-Lc));
}
} return sum;
} int main()
{
int T; scanf("%d", &T); while(T--)
{
Point p[MAXN], crs; scanf("%lf%lf%lf%lf", &p[].x, &p[].y, &p[].x, &p[].y);
scanf("%lf%lf%lf%lf", &p[].x, &p[].y, &p[].x, &p[].y);
Segment L1(p[], p[]), L2(p[], p[]); double ans = ; if(L1.Inter(L2) && L2.Inter(L1))
{
crs = L1.CrossNode(L2);
ans = Find(crs, p, );
} printf("%.2f\n", ans+EPS);
} return ;
}

An Easy Problem?! - POJ 2826(求面积)的更多相关文章

  1. POJ 1152 An Easy Problem! (取模运算性质)

    题目链接:POJ 1152 An Easy Problem! 题意:求一个N进制的数R.保证R能被(N-1)整除时最小的N. 第一反应是暴力.N的大小0到62.发现当中将N进制话成10进制时,数据会溢 ...

  2. hdu2601 An easy problem(数学)

    题目意思: http://acm.hdu.edu.cn/showproblem.php? pid=2601 给出一个数N,求N=i*j+i+j一共同拥有多少种方案. 题目分析: 此题直接暴力模拟就可以 ...

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

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

  4. POJ 2826 An Easy Problem? 判断线段相交

    POJ 2826 An Easy Problem?! -- 思路来自kuangbin博客 下面三种情况比较特殊,特别是第三种 G++怎么交都是WA,同样的代码C++A了 #include <io ...

  5. POJ 2826 An Easy Problem?!

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

  6. POJ 2826 An Easy Problem?! --计算几何,叉积

    题意: 在墙上钉两块木板,问能装多少水.即两条线段所夹的中间开口向上的面积(到短板的水平线截止) 解法: 如图: 先看是否相交,不相交肯定不行,然后就要求出P与A,B / C,D中谁形成的向量是指向上 ...

  7. POJ 2826 An Easy Problem?! 好的标题

    受该两块木板以形成槽的效果.Q槽可容纳雨水多,注意雨爆跌,思想是非常easy,分类讨论是有点差. 1.假定两条线段不相交或平行,然后再装0: 2.有一个平行x轴.连衣裙0. 3.若上面覆盖以下的,装0 ...

  8. 【解题报告】PKU 2826 An Easy Problem?!

    原题链接:http://poj.org/problem?id=2826 一题很蛋疼的一题.目前为止还有一个问题我没搞清楚,问题注在代码中. 题目大意: 外面下雨了,农民Johnoson的bull(?? ...

  9. poj 3348--Cows(凸包求面积)

    链接:http://poj.org/problem?id=3348 Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions:  ...

随机推荐

  1. ERROR ITMS-90167: "No .app bundles found in the package"

    http://stackoverflow.com/questions/37838487/error-itms-90167-no-app-bundles-found-in-the-package 简单说 ...

  2. 使用bind()扩充作用域

    window.color = "blue"; var o = {color :"red"}; function sayColor(){ alert(this.c ...

  3. JSONP技术原理及实现

    跨域问题一直是前端中常见的问题,每当说到跨域,第一浮现的技术必然就是JSONP JSONP在我的理解,它并不是ajax,它是在文档中插入一个script标签,创建_callback方法,通过服务器配合 ...

  4. java基础部分

    1.java的基本数据类型及所占的字节 boolen  8位  1个字节 byte 8位 1个字节 char 16位 2个字节 short 16位 2个字节 int 32位 4个字 float 32位 ...

  5. Activity singleTop启动模式

    栈顶单例模式 和standard模式一样,  只有Activity已经存在并且位于栈顶时, 不会重新创建. 其他时候都会创建新的Activity,然后放在栈顶

  6. Day20 Django之Model多对多、中间件、缓存、信号和分页

    一.Form补充 class IndexForm(forms.Form): # c = [ # (1, 'CEO'), # (2, 'CTO') # ] # 静态字段,属于IndexForm类,即使数 ...

  7. VC皮肤库之duilib

    首先是个国产的开源 的,directui 界面库,开放,共享,惠众,共赢,遵循bsd协议,可以免费用于商业项目,目前支持Windows 32 .Window CE.Mobile等平台. Duilib ...

  8. CocoaPods ADD private Spec Repo

    Private Pods CocoaPods is a great tool not only for adding open source code to your project, but als ...

  9. 通过javascript实现1~100内能同时被2和3整除的数并生成如下表格

    请通过javascript实现1~100内能同时被2和3整除的数并生成如下表格: <!DOCTYPE html><html lang="en"><he ...

  10. Action类一般情况为何要继承ActionSupport

    struts2中的action可以继承ActionSupport,也可以不继承ActionSupport.不继承ActionSupport的情况只需要有一个方法,返回String,即可,记住,在继承A ...