原题戳这里

开始一小段时间的POJ计算几何练习计划(估计很快就会被恶心回去)

题解

用一条平行于y轴的扫描线,计算两条扫描线之间多少格子被覆盖了

精度可tm变态了,可能是因为题目要求的关系吧,需要上取整和下取整,可能有一点误差也给算进去了,精度掉的很大

看一下上一次的上边界是哪里,不要重复计算

代码

#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <cstring>
#include <ctime>
#include <map>
#include <algorithm>
#include <cmath>
#define MAXN 100005
#define eps 1e-8
//#define ivorysi
#define PDD pair<db,db>
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long int64;
typedef double db;
int N;
bool dcmp(db a,db b) {
return fabs(a - b) < eps;
}
bool Gter(db a,db b) {
return a > b + eps;
}
struct Point {
db x,y;
Point() {}
Point(db _x,db _y) {
x = _x;y = _y;
}
friend Point operator + (const Point &a,const Point &b) {
return Point(a.x + b.x,a.y + b.y);
}
friend Point operator - (const Point &a,const Point &b) {
return Point(a.x - b.x,a.y - b.y);
}
friend Point operator / (const Point &a,const db &k) {
return Point(a.x / k,a.y / k);
}
friend Point operator * (const Point &a,const db &k) {
return Point(a.x * k,a.y * k);
}
friend db operator * (const Point &a,const Point &b) {
return a.x * b.y - a.y * b.x;
}
}P[205];
db dot(Point a,Point b) {
return a.x * b.x + a.y * b.y;
}
struct Seg {
Point a,b;
Seg() {}
Seg(Point _a,Point _b) {
a = _a;b = _b;
}
}Line[205];
PDD Y[205]; void Solve() {
int ans = 0;
int st = 2000,ed = -2000;
for(int i = 1 ; i <= N ; ++i) {
scanf("%lf%lf",&P[i].x,&P[i].y);
st = min(st,(int)P[i].x);
ed = max(ed,(int)P[i].x);
}
P[N + 1] = P[1];
for(int i = 1 ; i <= N ; ++i) {
if(P[i].x > P[i + 1].x) Line[i] = Seg(P[i + 1],P[i]);
else Line[i] = Seg(P[i],P[i + 1]);
}
for(int i = st ; i <= ed ; ++i) {
int cnt = 0;
for(int j = 1 ; j <= N ; ++j) {
if(Line[j].a.x <= i && Line[j].b.x >= i + 1) {
db a = Line[j].a.y + (i - Line[j].a.x) * (Line[j].b.y - Line[j].a.y) / (Line[j].b.x - Line[j].a.x);
db b = Line[j].a.y + (i - Line[j].a.x + 1) * (Line[j].b.y - Line[j].a.y) / (Line[j].b.x - Line[j].a.x);
Y[++cnt] = mp(a,b);
}
}
sort(Y + 1,Y + cnt + 1);
int last = -4001;
for(int j = 1 ; j <= cnt ; j += 2) {
int f = floor(min(Y[j].fi,Y[j].se));
int c = ceil(max(Y[j + 1].fi,Y[j + 1].se));
f = max(f,last);
ans += c - f;
last = c;
}
}
printf("%d\n",ans);
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
while(scanf("%d",&N) != EOF && N) {
Solve();
}
return 0;
}

【POJ】2043.Area of Polygons的更多相关文章

  1. 【POJ】1704 Georgia and Bob(Staircase Nim)

    Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, ...

  2. 【POJ】1067 取石子游戏(博弈论)

    Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...

  3. 【BZOJ】【1986】【USACO 2004 Dec】/【POJ】【2373】划区灌溉

    DP/单调队列优化 首先不考虑奶牛的喜欢区间,dp方程当然是比较显然的:$ f[i]=min(f[k])+1,i-2*b \leq k \leq i-2*a $  当然这里的$i$和$k$都是偶数啦~ ...

  4. 【POJ】【2104】区间第K大

    可持久化线段树 可持久化线段树是一种神奇的数据结构,它跟我们原来常用的线段树不同,它每次更新是不更改原来数据的,而是新开节点,维护它的历史版本,实现“可持久化”.(当然视情况也会有需要修改的时候) 可 ...

  5. 【POJ】1222 EXTENDED LIGHTS OUT

    [算法]高斯消元 [题解] 高斯消元经典题型:异或方程组 poj 1222 高斯消元详解 异或相当于相加后mod2 异或方程组就是把加减消元全部改为异或. 异或性质:00 11为假,01 10为真.与 ...

  6. 【POJ】2892 Tunnel Warfare

    [算法]平衡树(treap) [题解]treap知识见数据结构 在POJ把语言从G++换成C++就过了……??? #include<cstdio> #include<algorith ...

  7. 【POJ】【1637】Sightseeing tour

    网络流/最大流 愚人节快乐XD 这题是给一个混合图(既有有向边又有无向边),让你判断是否有欧拉回路…… 我们知道如果一个[连通]图中每个节点都满足[入度=出度]那么就一定有欧拉回路…… 那么每条边都可 ...

  8. 【poj】1001

    [题目] ExponentiationTime Limit: 500MS Memory Limit: 10000KTotal Submissions: 123707 Accepted: 30202De ...

  9. 【POJ】3070 Fibonacci

    [算法]矩阵快速幂 [题解] 根据f[n]=f[n-1]+f[n-2],可以构造递推矩阵: $$\begin{vmatrix}1 & 1\\ 1 & 0\end{vmatrix} \t ...

随机推荐

  1. SFTP上传下载文件、文件夹常用操作

    SFTP上传下载文件.文件夹常用操作 1.查看上传下载目录lpwd 2.改变上传和下载的目录(例如D盘):lcd  d:/ 3.查看当前路径pwd 4.下载文件(例如我要将服务器上tomcat的日志文 ...

  2. java io读写文件

    java io读写文件相关阅读:http://www.cnblogs.com/wing011203/archive/2013/05/03/3056535.html public class DemoI ...

  3. windows下静态编译pthread

    1. Building the library as a statically linkable library-------------------------------------------- ...

  4. python日记---day1

    Life is  short,Test in  python 一.输入输出 1.用print()在括号中加上字符串,就可以向屏幕上输出指定的文字.比如输出'hello, world' print('h ...

  5. Spark1.3.1 On Yarn的集群搭建

    下面给出的是spark集群搭建的环境: 操作系统:最小安装的CentOS 7(下载地址) Yarn对应的hadoop版本号:Hadoop的Cloudera公司发行版Hadoop2.6.0-CDH5.4 ...

  6. HDU 4548 美素数 在线打表加数状数组

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4548 解题报告:一开始本想先打个素数表,然后每次输入L 跟R 的时候都进行暴力判断,但这题测试数据太多 ...

  7. PHP autoload自动加载机制

    原文地址: http://www.jb51.net/article/31399.htm 一直不是很明白__autoload()和spl_autoload_register()到底有什么不同,找到了一个 ...

  8. sql____001

    题目: create table my_001 (id int,value int); insert into my_001 values(1,10): insert into my_001 valu ...

  9. Oracle数据库中几种常见的SCN

    控制文件中的SCN 数据文件头的SCN 数据块中的SCN 日志文件头中的SCN 事务SCN 内存中的SCN 一 控制文件中的SCN 1.1 数据库SCN 数据库SCN表示最近一次全量checkpoin ...

  10. webpack4.5.0+vue2.5.16+vue-loader 实战组件化开发案例以及版本问题中踩的一些大坑!!!

    一 vue-loader 我们先不管脚手架,只说vue-loader,简单讲就是可将.vue文件打包,实现组件化开发,即一个.vue文件就是一个组件,开发中只需要引入这个.vue组件就可以了! 然后. ...