C - How I Mathematician Wonder What You Are!解题报告(来自网络)
来源:互联网 发布:阿里云优惠口令看不懂 编辑:程序博客网 时间:2024/04/27 19:05
对于半平面交的一些简明扼要的介绍可以参考这篇博客:http://blog.csdn.net/accry/article/details/6070621。此外,这篇博客上介绍的还有我敲出的程序都只是比较好理解的O(n^2)的求半平面交的算法,对于O(nlogn)的算法可以参考朱泽园的论文。
由于这个题目指明了多边形上的点是按逆时针序给出的,因而就不用再将每组数据都其统一成某个顺序了。
#include<stdio.h>#include<string.h>#define MAXD 110#define zero 1e-8#define INF 100000struct point{ double x, y;}p[MAXD], wa[MAXD], wb[MAXD], *a, *b;int N, an, bn;double fabs(double x){ return x < 0 ? -x : x;}int dcmp(double x){ return fabs(x) < zero ? 0 : (x < 0 ? -1 : 1);}double det(double x1, double y1, double x2, double y2){ return x1 * y2 - x2 * y1;}void init(){ int i, j, k; for(i = 0; i < N; i ++) scanf("%lf%lf", &p[i].x, &p[i].y); p[N] = p[0];}void add(double x, double y){ b[bn].x = x, b[bn].y = y; ++ bn;}void cut(int k){ int i, j, tn; point *t; double x, y, t1, t2; bn = 0; for(i = 0; i < an; i ++) { t1 = det(p[k + 1].x - p[k].x, p[k + 1].y - p[k].y, a[i].x - p[k].x, a[i].y - p[k].y); t2 = det(p[k + 1].x - p[k].x, p[k + 1].y - p[k].y, a[i + 1].x - p[k].x, a[i + 1].y - p[k].y); if(dcmp(t1) >= 0) add(a[i].x, a[i].y); if(dcmp(t1) * dcmp(t2) < 0) { x = (fabs(t2) * a[i].x + fabs(t1) * a[i + 1].x) / (fabs(t1) + fabs(t2)); y = (fabs(t2) * a[i].y + fabs(t1) * a[i + 1].y) / (fabs(t1) + fabs(t2)); add(x, y); } } t = a, a = b, b = t; tn = an, an = bn, bn = tn; a[an] = a[0];}void solve(){ int i, j, k; a = wa, b = wb; an = 4; a[0].x = -INF, a[0].y = -INF, a[1].x = INF, a[1].y = -INF, a[2].x = INF, a[2].y = INF, a[3].x = -INF, a[3].y = INF; a[4] = a[0]; for(i = 0; i < N; i ++) cut(i); if(an == 0) printf("0\n"); else printf("1\n");}int main(){ for(;;) { scanf("%d", &N); if(!N) break; init(); solve(); } return 0;}
- C - How I Mathematician Wonder What You Are!解题报告(来自网络)
- poj 3130 How I Mathematician Wonder What You Are!
- POJ 3130 How I Mathematician Wonder What You Are!
- POJ 3130 How I Mathematician Wonder What You Are!
- poj 3130 How I Mathematician Wonder What You Are!
- POJ 3130 How I Mathematician Wonder What You Are!
- POJ 3130 How I Mathematician Wonder What You Are!
- POJ 3130 || How I Mathematician Wonder What You Are!
- poj 3130 How I Mathematician Wonder What You Are!
- POJ 3130 How I Mathematician Wonder What You Are! 笔记
- How I Mathematician Wonder What You Are! POJ
- poj 3130 How I Mathematician Wonder What You Are!(半平面交)
- POJ 3130 How I Mathematician Wonder What You Are! (半平面交+多边形内核判断)
- poj 3130 How I Mathematician Wonder What You Are! (半平面交)
- [POJ3130]How I Mathematician Wonder What You Are!(半平面交)
- poj_3130 How I Mathematician Wonder What You Are!(半平面交)
- POJ 3130 & ZOJ 2820 How I Mathematician Wonder What You Are!(半平面相交 多边形是否有核)
- POJ 3130 How I Mathematician Wonder What You Are!(半平面交求多边形的核)
- 中医揭秘:十二星座体质容易得什么病
- 在编爱恩斯坦棋(3)
- 十二星座养生保健法
- A - Wall解题报告(来自网络)
- B - Scrambled Polygon
- C - How I Mathematician Wonder What You Are!解题报告(来自网络)
- D - Area解题报告(熊禾强)
- E - Pipe解题报告(来自网络)
- F - Pipe Fitters解题报告(熊禾强)
- G - There's Treasure Everywhere!解题报告(熊禾强)
- H - Area in Triangle解题报告(熊禾强)
- I - I Think I Need a Houseboat解题报告(熊禾强)
- J - Transmitters解题报告(熊禾强)
- K - Parallelogram Counting解题报告(来自网络)