POJ 3130
这题,加了精度错了,不加精度反而对了。。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAXN=110;
const double eps=1e-8; struct point {
double x,y;
};
point pts[MAXN],p[MAXN],q[MAXN];
int n,cCnt,curCnt; int DB(double d){
if(d>eps) return 1;
if(d<-eps) return -1;
return 0;
} void initial(){
for(int i=1;i<=n;i++)
p[i]=pts[i];
p[n+1]=p[1];
p[0]=p[n];
cCnt=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);
point pt;
pt.x=(x.x * v + y.x * u) / (u + v);
pt.y=(x.y * v + y.y * u) / (u + v);
return pt;
} void cut(double a,double b,double c){
curCnt=0;
for(int i=1;i<=cCnt;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] = q[1];p[0] = p[curCnt];
cCnt = curCnt;
} void slove(){
initial();
for(int i=1;i<=n;i++){
double a,b,c;
getline(pts[i],pts[i+1],a,b,c);
cut(a,b,c);
}
} int main(){
while(true){
scanf("%d",&n);
if(n==0) break;
for(int i=1;i<=n;i++)
scanf("%lf%lf",&pts[i].x,&pts[i].y);
pts[n+1]=pts[1];
slove();
if(cCnt>=1) printf("1\n");
else printf("0\n");
}
return 0;
}
POJ 3130的更多相关文章
- POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交
题意:逆时针给出N个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...
- poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核 - 模版
/* poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核 */ #include <stdio.h> #include ...
- 三道半平面交测模板题 Poj1474 Poj 3335 Poj 3130
求半平面交的算法是zzy大神的排序增量法. ///Poj 1474 #include <cmath> #include <algorithm> #include <cst ...
- POJ 3130 How I Mathematician Wonder What You Are! (半平面交)
题目链接:POJ 3130 Problem Description After counting so many stars in the sky in his childhood, Isaac, n ...
- poj 3130 How I Mathematician Wonder What You Are!
http://poj.org/problem?id=3130 #include <cstdio> #include <cstring> #include <algorit ...
- poj 3335 /poj 3130/ poj 1474 半平面交 判断核是否存在 / poj1279 半平面交 求核的面积
/*************** poj 3335 点序顺时针 ***************/ #include <iostream> #include <cmath> #i ...
- POJ 3130 How I Mathematician Wonder What You Are!(半平面交求多边形的核)
题目链接 题意 : 给你一个多边形,问你该多边形中是否存在一个点使得该点与该多边形任意一点的连线都在多边形之内. 思路 : 与3335一样,不过要注意方向变化一下. #include <stdi ...
- How I Mathematician Wonder What You Are! - POJ 3130(求多边形的核)
题目大意:判断多多边形是否存在内核. 代码如下: #include<iostream> #include<string.h> #include<stdio.h> # ...
- How I Mathematician Wonder What You Are!(poj 3130)
题意:求问多边形的核(能够看到所有点的点)是否存在. /* 对于这样的题目,我只能面向std编程了,然而还是不理解. 算法可参考:http://www.cnblogs.com/huangxf/p/40 ...
- poj 3130 How I Mathematician Wonder What You Are! 【半平面交】
求多边形的核,直接把所有边求半平面交判断有无即可 #include<iostream> #include<cstdio> #include<algorithm> # ...
随机推荐
- B4321 queue2 dp
这个题的dp真的恶心.首先,一开始我以为是一道数论题,但是组合数和这个题没啥关系.dp方程巨麻烦,状态是dp[i][j][0/1],代表i位连了j个,上一位是否连着.然后开始转移,证明如下: 我们先来 ...
- 基于Spark的网站日志分析
本文只展示核心代码,完整代码见文末链接. Web Log Analysis 提取需要的log信息,包括time, traffic, ip, web address 进一步解析第一步获得的log信息,如 ...
- 捣鼓TinyMCE粘贴图片并上传+Flask后台
好久没有编程了,最近需要完成一个小功能,为了方便,需要粘贴图片后上传到后台.前台编辑器用tinymce(N年前用过,我也就知道这个编辑器而已.这次使用下来感觉文档更丰富了),后台我用的Flask.昨天 ...
- SpringMVC中url映射到Controller
SpringMVC也是一种基于请求驱动的WEB框架,并且使用了前端控制器的设计模式.前端控制器就是DispatcherServlet控制器,只要满足web.xml文件中的[url-pattern]的规 ...
- POJ 3322 Bloxorz I
首先呢 这个题目的名字好啊 ORZ啊 如果看不懂题意的话 请戳这里 玩儿几盘就懂了[微笑] http://www.albinoblacksheep.com/games/bloxorz 就是这个神奇的木 ...
- nginx编译安装新模块
nginx的模块是需要重新编译nginx,而不是像apache一样配置文件引用.so 这里以安装第三方ngx_http_google_filter_module模块为例 下载第三方扩展模块ngx_ht ...
- supervisord 使用记录
#supervisor简介 Supervisor是一个 Python 开发的 client/server 系统,可以管理和监控类 UNIX 操作系统上面的进程. #组成部分 supervisord(s ...
- 6月10遇到的bug
3.遇到的BUG 1.@Service(version = "1.0.0", interfaceClass = TransactionItemService.clas ...
- HTML+CSS(10)
n 组合选择器 多元素选择器 n 描述:给多个元素加同一个样式,多个选择器之间用逗号隔开. n 举例:h1,p,div,body{color:red;} 后代元素选择器(最常用) n 描述:给 ...
- 【C++】cin、cout的效率比scanf和printf低的解决方法
玩竞赛的同学应该发现了C++中直接调用cout.cin的效率要比printf和scanf的效率要低. 要解决这个问题,只需要在前面加上一句 std::ios::sync_with_stdio(fals ...