POJ_3335_Rotating Scoreboard(半平面交的核)
来源:互联网 发布:朱棣是朱元璋亲生 知乎 编辑:程序博客网 时间:2024/06/10 04:56
题型:计算几何
题意:判断多边形是否存在核
分析:半平面交模板题
代码:
#include<iostream>#include<cstring>#include<cmath>#include<cstdio>#define mt(a,b) memset(a,b,sizeof(a))using namespace std;const int maxn = 1234;const int inf=0x7ffffff;const double PI=acos(-1.0);const double eps=1e-8;const double e=2.7182818284590452354;struct point { double x,y; point() {} point(double x,double y): x(x),y(y) {}} p[maxn],q[maxn],pnt[maxn];int cnt,curcnt;void initial(int n) { for(int i=1; i<=n; i++) p[i]=pnt[i]; p[n+1]=p[1]; p[0]=p[n]; cnt=n;}//两点确定直线void getline(point x,point y,double &a,double &b,double &c) { a=y.y-x.y; b=x.x-y.x; c=y.x*x.y-x.x*y.y;}//求交点point intersect(point x,point y,double a,double b,double c) { double u=fabs(a*x.x+b*x.y+c); double v=fabs(a*y.x+b*y.y+c); return point((v*x.x+u*y.x)/(u+v),(v*x.y+u*y.y)/(u+v));}//直线切割void cut(double a,double b,double c) { curcnt=0; for(int i=1; i<=cnt; i++) { if(a*p[i].x+b*p[i].y+c>=0)//当前点在直线右侧 q[++curcnt]=p[i]; else { if(a*p[i-1].x+b*p[i-1].y+c>0)//前一个点在直线右侧 q[++curcnt]=intersect(p[i],p[i-1],a,b,c); if(a*p[i+1].x+b*p[i+1].y+c>0)//同理 q[++curcnt]=intersect(p[i],p[i+1],a,b,c); } } for(int i=1; i<=curcnt; i++) p[i]=q[i]; p[curcnt+1]=p[1]; p[0]=p[curcnt]; cnt=curcnt;}int main() { int n,t; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%lf%lf",&pnt[i].x,&pnt[i].y); pnt[n+1]=pnt[1]; initial(n); //顺时针方向 for(int i=1; i<=n; i++) { double a,b,c; getline(pnt[i],pnt[i+1],a,b,c); cut(a,b,c); } if(cnt<1) puts("NO"); else puts("YES"); } return 0;}
0 0
- POJ_3335_Rotating Scoreboard(半平面交的核)
- POJ 3335 Rotating Scoreboard 半平面的交
- poj 3335 Rotating Scoreboard - 半平面交
- POJ 3335 Rotating Scoreboard (半平面交)
- Rotating Scoreboard - POJ 3335 半平面交
- POJ 3335 Rotating Scoreboard 半平面交
- POJ 3335 Rotating Scoreboard 半平面交
- poj_3335 Rotating Scoreboard(半平面交)
- poj 3335 Rotating Scoreboard(半平面交)
- poj3335 Rotating Scoreboard【半平面交】
- POJ 3130 How I Mathematician Wonder What You Are! & 3335 Rotating Scoreboard (半平面交求多边形的核)
- poj 3335 Rotating Scoreboard(判断多边形是否有核+半平面交)
- POJ 3335 Rotating Scoreboard(半平面交 多边形是否有核 模板)
- poj 3335 Rotating Scoreboard(半平面交)
- [poj 3335]Rotating Scoreboard[半平面交模板题]
- poj 3335 Rotating Scoreboard(半平面交)
- POJ 3335 Rotating Scoreboard 半平面交求多边形内核
- POJ3335Rotating Scoreboard【半平面交判断多边形是否存在内核】
- Java (JDK7)中的String常量和String.intern的实现
- 文件头分析
- 如何下载googlecode源码webrtc、 如何下载更新Android SDK
- Codeforces Round #FF (Div. 2) C
- android 内存泄漏分析过程详解
- POJ_3335_Rotating Scoreboard(半平面交的核)
- G.MaxArea(SCUT 2014 春季选拔第一场 补充)
- 栈的应用举例2(迷宫求解)
- 【排列组合】有序进行全排列的几种方法
- Web编程中,常见的乱码解决方案
- linux网站
- POJ 2386 Lake Counting 搜索题解
- 解密Twitch:一家游戏直播网站缘何价值10亿刀?
- Android 设置横屏竖屏