poj 2540 Hotter Colder 切割多边形
- /*
- poj 2540 Hotter Colder 切割多边形
- 用两点的中垂线切割多边形,根据冷热来判断要哪一半
- 然后输出面积
- */
- #include <stdio.h>
- #include<math.h>
- const double eps=1e-8;
- const int N=200;
- struct point
- {
- double x,y;
- point(){}
- point(double a,double b):x(a),y(b){}
- }dian[N];
- point jiao[N];
- inline bool mo_ee(double x,double y)
- {
- double ret=x-y;
- if(ret<0) ret=-ret;
- if(ret<eps) return 1;
- return 0;
- }
- inline bool mo_gg(double x,double y) { return x > y + eps;} // x > y
- inline bool mo_ll(double x,double y) { return x < y - eps;} // x < y
- inline bool mo_ge(double x,double y) { return x > y - eps;} // x >= y
- inline bool mo_le(double x,double y) { return x < y + eps;} // x <= y
- inline double mo_xmult(point p2,point p0,point p1)//p1在p2左返回负,在右边返回正
- {
- return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
- }
- point mo_intersection(point u1,point u2,point v1,point v2)
- {
- point ret=u1;
- double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
- /((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
- ret.x+=(u2.x-u1.x)*t;
- ret.y+=(u2.y-u1.y)*t;
- return ret;
- }
- /////////////////////////
- //求法向量
- point mo_getfaxian(point xiang)
- {
- point a;
- if(mo_ee(xiang.x,0))
- {
- a.x=1;
- a.y=0;
- return a;
- }else if(mo_ee(xiang.y,0))
- {
- a.x=0;
- a.y=1;
- return a;
- }else
- {
- a.x=1;
- a.y=-1.0*xiang.x/xiang.y;
- return a;
- }
- }
- //求多边形面积
- double mo_area_polygon(point *dian,int n)
- {
- int i;
- point yuan;
- yuan.x=yuan.y=0;
- double ret=0;
- for(i=0;i<n;++i)
- {
- ret+=mo_xmult(dian[(i+1)%n],yuan,dian[i]);
- }
- if(ret<0) ret=-ret;
- return ret/2;
- }
- point mo_banjiao_jiao_temp[N*2];
- void mo_banjiao_cut(point *ans,point qian,point hou,int &nofdian)
- {
- int i,k;
- for(i=k=0;i<nofdian;++i)
- {
- double a,b;
- a=mo_xmult(hou,ans[i],qian);
- b=mo_xmult(hou,ans[(i+1)%nofdian],qian);
- if(mo_ge(a,0))//顺时针就是<=0
- {
- mo_banjiao_jiao_temp[k++]=ans[i];
- }if(mo_ll(a*b,0))
- {
- mo_banjiao_jiao_temp[k++]=mo_intersection(qian,hou,ans[i],ans[(i+1)%nofdian]);
- }
- }
- for(i=0;i<k;++i)
- {
- ans[i]=mo_banjiao_jiao_temp[i];
- }
- nofdian=k;
- }
- int main()
- {
- point qian(0,0);
- point cur,mid,end;
- char order[20];
- int flag=0;
- jiao[0]=point(0,0);
- jiao[1]=point(10,0);
- jiao[2]=point(10,10);
- jiao[3]=point(0,10);
- int jiaodian=4;
- while(scanf("%lf",&cur.x)!=EOF)
- {
- scanf("%lf%s",&cur.y,order);
- getchar();
- if(order[0]=='S'||flag==1)
- {
- flag=1;
- printf("0.00\n");
- continue;
- }
- mid.x=(cur.x+qian.x)/2;
- mid.y=(cur.y+qian.y)/2;
- end=mo_getfaxian(point(cur.x-qian.x,cur.y-qian.y));
- end.x=mid.x+end.x;
- end.y=mid.y+end.y;
- bool zai=mo_gg(mo_xmult(end,cur,mid),0);
- if((order[0]=='H'&&zai)||(order[0]=='C'&&(!zai)))
- {
- }else
- {
- point tem=end;
- end=mid;
- mid=tem;
- }
- mo_banjiao_cut(jiao,mid,end,jiaodian);
- double area=mo_area_polygon(jiao,jiaodian);
- printf("%.2lf\n",area);
- qian=cur;
- }
- return 0;
- }
poj 2540 Hotter Colder 切割多边形的更多相关文章
- POJ 2540 Hotter Colder(半平面交)
Description The children's game Hotter Colder is played as follows. Player A leaves the room while p ...
- POJ 2540 Hotter Colder --半平面交
题意: 一个(0,0)到(10,10)的矩形,目标点不定,从(0,0)开始走,如果走到新一点是"Hotter",那么意思是离目标点近了,如果是"Colder“,那么就是远 ...
- POJ 2540 Hotter Colder
http://poj.org/problem?id=2540 题意:给你每次行走的路径,而且告诉你每次离一个点光源是远了还是近了,要求每次光源可能存在的位置的面积. 思路:如果出现"same ...
- poj 1474 Video Surveillance - 求多边形有没有核
/* poj 1474 Video Surveillance - 求多边形有没有核 */ #include <stdio.h> #include<math.h> const d ...
- 【题解】切割多边形 [SCOI2003] [P4529] [Bzoj1091]
[题解]切割多边形 [SCOI2003] [P4529] [Bzoj1091] 传送门:切割多边形 \(\text{[SCOI2003] [P4529]}\) \(\text{[Bzoj1091]}\ ...
- poj 1514 Metal Cutting (dfs+多边形切割)
1514 -- Metal Cutting 一道类似于半平面交的题. 题意相当简单,给出一块矩形以及最后被切出来的的多边形各个顶点的位置.每次切割必须从一端切到另一端,问切出多边形最少要切多长的距离. ...
- bzoj1091: [SCOI2003]切割多边形
Description 有一个凸p边形(p<=8),我们希望通过切割得到它.一开始的时候,你有一个n*m的矩形,即它的四角的坐标分别为(0,0), (0,m), (n,0), (n,m).每次你 ...
- poj 3525 半平面交求多边形内切圆最大半径【半平面交】+【二分】
<题目链接> 题目大意:给出一个四面环海的凸多边形岛屿,求出这个岛屿中的点到海的最远距离. 解题分析: 仔细思考就会发现,其实题目其实就是让我们求该凸多边形内内切圆的最大半径是多少.但是, ...
- POJ 1265 Area (Pick定理 & 多边形面积)
题目链接:POJ 1265 Problem Description Being well known for its highly innovative products, Merck would d ...
随机推荐
- 指定端口号,多线程扫描局域网内IP地址
小白第一次发博客,请各路大神不要喷,有错的地方还请不吝啬指教,谢谢....... 因为注释基本上已经说清楚啦,在这里就不多说什么啦,知识不够怕误人子弟 # -*- coding:utf-8 -*-im ...
- Promise原理 && 简单实现
Promise原理 参考https://github.com/chunpu/promise/blob/master/promise.js 个人认为原博的实现有点问题 在next函数的实现上, 会导致无 ...
- 【Chromium中文文档】沙箱FAQ
沙箱FAQ 转载请注明出处:https://ahangchen.gitbooks.io/chromium_doc_zh/content/zh//General_Architecture/Sandbox ...
- CC++初学者编程教程(14) Redhat linux安装Oracle12c
1选择虚拟机的设置 2 设置共享文件夹 3 使用共享文件夹向导 4 选择主机路径 5 启用文件共享 6 设置好文件共享以后,关闭虚拟机的设置 7 开启虚拟机 8 登陆 9输入密码 10 安装vmwar ...
- error: ld returned 1 exit status 和 error:undefined reference
undefined reference 往往是链接时出现错误,无法解析引用.这篇文章总结的很好undefined reference问题总结 error: ld returned 1 exit sta ...
- CSS滤镜让图片模糊(毛玻璃效果)实例页面
<pre name="code" class="css">CSS代码: .blur { filter: url(blur.svg#blur); /* ...
- List的方法和属性 方法或属性 作用
List的方法和属性 方法或属性 作用 Capacity 用于获取或设置List可容纳元素的数量.当数量超过容量时,这个值会自动增长.您可以设置这个值以减少容量,也可以调用trin()方法来减少容量以 ...
- JQuery日记6.9 Promise/A之Callbacks
JQuery并没有简单的使用一个Array来存储回调函数,而是通过JQuery.Callbacks(options)返回一个self对象,此对象能够动态的add,remove和fire回调函数队列.此 ...
- Linux下patch打补丁命令
此命令用于为特定软件包打补丁,他使用diff命令对源文件进行操作. 基本命令语法: patch [-R] {-p(n)} [--dry-run] < patch_file_name p:为pat ...
- iOS获取本地ip(基本通用)
今天有个朋友问我怎样訪问手机ip,上网找了几个,用了近200多行代码,最后发现头文件用的居然还是Linux中的,OC没有这个头文件.感觉socket本身应该能够后去自己的ip就试了一下,果然7.8行代 ...