题意: 一个(0,0)到(10,10)的矩形,目标点不定,从(0,0)开始走,如果走到新一点是"Hotter",那么意思是离目标点近了,如果是"Colder“,那么就是远了,"Same"是相同。要你推测目标点的可能位置的面积。

解法:半平面交水题。从一个点到另一个点远了,说明目标点在两点之间连线的中垂线的离源点较近的一侧,即我们每次都可以得到一条直线来切割平面,要么切割左侧,要么切割右侧,要么都切,再求一个半平面交就可以得出可能面积了。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define pi acos(-1.0)
#define eps 1e-8
using namespace std; struct Point{
double x,y;
Point(double x=, double y=):x(x),y(y) {}
void input() { scanf("%lf%lf",&x,&y); }
};
typedef Point Vector;
struct Line{
Point p;
Vector v;
double ang;
Line(){}
Line(Point p, Vector v):p(p),v(v) { ang = atan2(v.y,v.x); }
Point point(double t) { return Point(p.x + t*v.x, p.y + t*v.y); }
bool operator < (const Line &L)const { return ang < L.ang; }
};
int dcmp(double x) {
if(x < -eps) return -;
if(x > eps) return ;
return ;
}
template <class T> T sqr(T x) { return x * x;}
Vector operator + (Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y); }
Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y); }
Vector operator * (Vector A, double p) { return Vector(A.x*p, A.y*p); }
Vector operator / (Vector A, double p) { return Vector(A.x/p, A.y/p); }
bool operator < (const Point& a, const Point& b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }
bool operator >= (const Point& a, const Point& b) { return a.x >= b.x && a.y >= b.y; }
bool operator <= (const Point& a, const Point& b) { return a.x <= b.x && a.y <= b.y; }
bool operator == (const Point& a, const Point& b) { return dcmp(a.x-b.x) == && dcmp(a.y-b.y) == ; }
double Dot(Vector A, Vector B) { return A.x*B.x + A.y*B.y; }
double Length(Vector A) { return sqrt(Dot(A, A)); }
double Angle(Vector A, Vector B) { return acos(Dot(A, B) / Length(A) / Length(B)); }
double Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; }
Vector VectorUnit(Vector x){ return x / Length(x);}
Vector Normal(Vector x) { return Point(-x.y, x.x) / Length(x);}
double angle(Vector v) { return atan2(v.y, v.x); } Point GetLineIntersection(Line A, Line B) {
Vector u = A.p - B.p;
double t = Cross(B.v, u) / Cross(A.v, B.v);
return A.p + A.v*t;
}
double DisP(Point A,Point B) {
return Length(B-A);
}
double CalcConvexArea(Point* p,int n) { //凸包面积
double area = 0.0;
for(int i=;i<n-;i++)
area += Cross(p[i]-p[],p[i+]-p[]);
return fabs(area*0.5);
}
bool OnLeft(Line L, Point p) { return dcmp(Cross(L.v,p-L.p)) > ; }
bool CmpPolarLine(Line a,Line b) { //直线极角排序
return angle(a.v) < angle(b.v);
}
int HalfPlaneIntersection(Line* L, int n, Point* poly) { //半平面交点存入poly
sort(L,L+n,CmpPolarLine);
int first,last;
Point *p = new Point[n];
Line *q = new Line[n];
q[first=last=] = L[];
for(int i=;i<n;i++) {
while(first < last && !OnLeft(L[i],p[last-])) last--;
while(first < last && !OnLeft(L[i],p[first])) first++;
q[++last] = L[i];
if(dcmp(Cross(q[last].v, q[last-].v)) == ) {
last--;
if(OnLeft(q[last], L[i].p)) q[last] = L[i];
}
if(first < last) p[last-] = GetLineIntersection(q[last-],q[last]);
}
while(first < last && !OnLeft(q[first],p[last-])) last--;
if(last-first <= ) return ; //点或线或无界平面,返回0
p[last] = GetLineIntersection(q[last],q[first]);
int m = ;
for(int i=first;i<=last;i++) poly[m++] = p[i];
delete p; delete q;
return m;
} Line L[],TL[];
Point poly[]; int main()
{
int i,j,tot = -;
Point n,p;
char ss[];
p.x = p.y = 0.0;
TL[++tot] = Line(Point(,),Vector(,));
TL[++tot] = Line(Point(,),Vector(,));
TL[++tot] = Line(Point(,),Vector(-,));
TL[++tot] = Line(Point(,),Vector(,-));
while(scanf("%lf%lf%s",&n.x,&n.y,ss)!=EOF)
{
if(ss[] == 'H')
TL[++tot] = Line(Point((n.x+p.x)/2.0,(n.y+p.y)/2.0),Vector(Normal(p-n)));
else if(ss[] == 'C')
TL[++tot] = Line(Point((n.x+p.x)/2.0,(n.y+p.y)/2.0),Vector(Normal(n-p)));
else {
TL[++tot] = Line(Point((n.x+p.x)/2.0,(n.y+p.y)/2.0),Vector(Normal(p-n)));
TL[++tot] = Line(Point((n.x+p.x)/2.0,(n.y+p.y)/2.0),Vector(Normal(n-p)));
}
p = n;
for(i=;i<=tot;i++) L[i] = TL[i];
int m = HalfPlaneIntersection(L,tot+,poly);
if(!m) puts("0.00");
else printf("%.2f\n",CalcConvexArea(poly,m));
}
return ;
}

POJ 2540 Hotter Colder --半平面交的更多相关文章

  1. poj 2540 Hotter Colder 切割多边形

    /* poj 2540 Hotter Colder 切割多边形 用两点的中垂线切割多边形,根据冷热来判断要哪一半 然后输出面积 */ #include <stdio.h> #include ...

  2. POJ 2540 Hotter Colder(半平面交)

    Description The children's game Hotter Colder is played as follows. Player A leaves the room while p ...

  3. POJ 2540 Hotter Colder

    http://poj.org/problem?id=2540 题意:给你每次行走的路径,而且告诉你每次离一个点光源是远了还是近了,要求每次光源可能存在的位置的面积. 思路:如果出现"same ...

  4. 2018.07.03 POJ 1279Art Gallery(半平面交)

    Art Gallery Time Limit: 1000MS Memory Limit: 10000K Description The art galleries of the new and ver ...

  5. POJ 3335 Rotating Scoreboard 半平面交求核

    LINK 题意:给出一个多边形,求是否存在核. 思路:比较裸的题,要注意的是求系数和交点时的x和y坐标不要搞混...判断核的顶点数是否大于1就行了 /** @Date : 2017-07-20 19: ...

  6. POJ 1474 Video Surveillance 半平面交/多边形核是否存在

    http://poj.org/problem?id=1474 解法同POJ 1279 A一送一 缺点是还是O(n^2) ...nlogn的过几天补上... /********************* ...

  7. POJ 1279 Art Gallery 半平面交/多边形求核

    http://poj.org/problem?id=1279 顺时针给你一个多边形...求能看到所有点的面积...用半平面对所有边取交即可,模版题 这里的半平面交是O(n^2)的算法...比较逗比.. ...

  8. POJ 1279 Art Gallery 半平面交求多边形核

    第一道半平面交,只会写N^2. 将每条边化作一个不等式,ax+by+c>0,所以要固定顺序,方便求解. 半平面交其实就是对一系列的不等式组进行求解可行解. 如果某点在直线右侧,说明那个点在区域内 ...

  9. POJ 1755 Triathlon (半平面交)

    Triathlon Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4733   Accepted: 1166 Descrip ...

随机推荐

  1. 使用XmlHelper添加节点C#代码

    接着上一篇:http://keleyi.com/a/bjac/ttssua0f.htm在前篇文章中,给出了C# XML文件操作类XmlHelper的代码,以及使用该类的一个例子,即使用XmlHelpe ...

  2. 极富创意的3D文件夹切换效果

    今天分享的是一个极富创意的文件夹切换效果.这个案例使用CSS 3动画实现了一个3D的平行六面体旋转效果.点击顶部的3个按钮可以旋转并切换.另外,每个六面体本身是一个文件夹,点击后可以展开查看里面的详情 ...

  3. 【MVC学习笔记01】初窥奥秘

    前言 最近工作落实了,是我非常喜欢的无线前端,会接触很多新东西啦,需要努力才行.因为会用到backbone,所以要学习MVC啦. MVC(模型-视图-控制器),这种模式最早被用于构建桌面程序和服务器端 ...

  4. 【Leafletjs】5.L.Control 自定义一个Control

    L.Control 所有leaflet控制的基础类.继承自IControl接口. 你可以这样添加控件: control.addTo(map); // the same as map.addContro ...

  5. [android]AndroidInject框架——我的第一个android小型框架

    作为一个移动应用开发者,随着需求的日益增多,Android项目的越来越臃肿,代码量越来越大, 现在冷静下来回头看看我们的代码,有多少代码跟业务逻辑没什么关系的 所以,本人自不量力,在github上建了 ...

  6. Git 撤销修改

    Git 撤销修改 增补提交 git commit –C HEAD –a --amend -C表示复用指定提交的提交留言,这个例子中是HEAD,实际上可以指定其他有效的提交名称. 如果参数是小写的-c, ...

  7. GDataXMLNode应用

    一.GDataXMLNode的安装配置过程 1.将GDataXMLNode文件加入至工程中 2.向Frameworks文件中添加libxml2.dylib库 3.在Croups & Files ...

  8. 你真的了解UIView吗?

    一:首先查看一下关于UIView的定义 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIView : UIResponder <NSCoding, UIAppe ...

  9. 【原+转】用CMake代替makefile进行跨平台交叉编译

    在开始介绍如何使用CMake编译跨平台的静态库之前,先讲讲我在没有使用CMake之前所趟过的坑.因为很多开源的程序,比如png,都是自带编译脚本的.我们可以使用下列脚本来进行编译: ./configu ...

  10. Sqlite学习笔记(五)&&SQLite封锁机制

    概述 SQLite虽然是一个轻量的嵌入式数据库,但这并不影响它支持事务.所谓支持事务,即需要在并发环境下,保持事务的ACID特性.事务的原子性,隔离性都需要通过并发控制来保证.那么Sqlite的并发控 ...