同swustoj 169
Interior Points of Lattice Polygons
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 229   Accepted: 152

Description

lattice point is a point with integer coordinates. A lattice polygon is a polygon with all vertices lattice points.

The lattice points on the boundary of the polygon are boundary points (open dots in the figure above) and the points inside and not on the polygon are interior points (filled in dots in the figure above).

A polygon is convex if any line segment between two points of the polygon is inside (or on the boundary of) the polygon. Equivalently, the interior angle at each polygon vertex is less than 180 degrees. Note that any line between two points inside (and not on the boundary of) the polygon is entirely inside (and not on the boundary of) the polygon.

The interior points of a convex lattice polygon on any horizontal line form a single segment from a leftmost point to a rightmost point (which may be the same). Note that there may be no interior points (A), or only one (B), or isolated points (C) as shown in the figures below.

Write a program that reads the vertices of a convex lattice polygon in standard order and outputs the interior points as a list of horizontal line segments. The vertices of a lattice polygon are in standard order if: 
a) The first vertex is the one with the largest y value. If two vertices have the same y value, the one with the smaller x value is the first. 
b) Vertices are given in clockwise order around the polygon.

Input

The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. The first line of each data set contains the data set number, followed by a space, followed by a decimal integer giving the number vertices N, (3 ≤ N ≤ 50), of the polygon. The remaining lines in the data set contain the vertices, one per line in standard order. Each line contains the decimal integer x coordinate, a space and the decimal integer y coordinate.

Output

For each data set there are multiple lines of output. The first line contains a decimal integer giving the data set number followed by a single space, followed by a decimal integer giving the number of horizontal lines which contain interior points (this may be zero (0) or more). The lines of interior points, if any, follow, one per line in order of decreasing y value. Each line contains the decimal integer y coordinate, a single space and the decimal integer x coordinate of the left most point, a single space and the decimal integer x coordinate of the right most point.

Sample Input

6
1 8
5 10
8 9
11 6
10 2
6 0
1 1
0 4
2 8
2 4
3 10
13 7
10 -3
0 0
3 3
1 3
3 1
1 1
4 3
1 4
4 1
1 1
5 4
0 6
2 3
3 0
1 3
6 6
1 3
3 3
4 2
3 1
1 1
0 2

Sample Output

1 9
9 4 7
8 3 8
7 2 9
6 2 10
5 1 10
4 1 10
3 1 10
2 1 9
1 2 7
2 12
9 3 6
8 3 9
7 3 12
6 2 12
5 2 12
4 2 12
3 1 11
2 1 11
1 1 11
0 1 10
-1 4 10
-2 7 10
3 0
4 1
2 2 2
5 2
4 1 1
2 2 2
6 1
2 1 3

题意:给出一个凸多边形,求在其内部的格点

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
using namespace std;
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define EPS 1e-10
#define N 1010 int dcmp(double x)
{
if(fabs(x)<EPS) return ;
return x<?-:;
}
struct Point
{
double x,y;
Point (){}
Point (double x,double y):x(x),y(y){}
Point operator - (Point p){
return Point(x-p.x,y-p.y);
}
double operator * (Point p){
return x*p.x+y*p.y;
}
double operator ^ (Point p){
return x*p.y-y*p.x;
}
bool operator < (const Point &p)const
{
if(y!=p.y) return y>p.y;
return x<p.x;
}
};
struct Line
{
Point s,e;
Line (){}
Line (Point s,Point e):s(s),e(e){}
};
bool PointOnSeg(Line l,Point p)
{
return dcmp((l.s-p)^(l.e-p))== && dcmp((l.s-p)*(l.e-p))<=;
}
int PointInConvexPoly(Point p[],Point q,int n)
{
for(int i=;i<n;i++){
if(dcmp((p[i]-q)^(p[(i+)%n]-q))>) return -;
if(PointOnSeg(Line(p[i],p[(i+)%n]),q)) return ;
}
return ;
}
int main()
{
int n;
int T,iCase;
Point p[];
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&iCase,&n);
double mxx,mix,mxy,miy;
mix=miy=INF;
mxx=mxy=-INF;
for(int i=;i<n;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
mix=min(mix,p[i].x);
mxx=max(mxx,p[i].x);
miy=min(miy,p[i].y);
mxy=max(mxy,p[i].y);
}
int k=;
Point q[];
for(int i=mix;i<=mxx;i++){
for(int j=miy;j<=mxy;j++){
if(PointInConvexPoly(p,Point(i,j),n)==){
q[k++]=Point(i,j);
}
}
}
if(k==){
printf("%d 0\n",iCase);
continue;
}
sort(q,q+k);
int i,j,cnt=;
for(i=;i<k;i++) if(q[i].y!=q[i-].y) cnt++;
printf("%d %d\n",iCase,cnt);
for(i=;i<k;i++){
printf("%g %g",q[i].y,q[i].x);
for(j=i+;j<k;j++){
if(q[j].y!=q[i].y) break;
}
printf(" %g",q[j-].x);
printf("\n");
i=j-;
}
}
return ;
}

[POJ 3788] Interior Points of Lattice Polygons的更多相关文章

  1. POJ 3805 Separate Points (判断凸包相交)

    题目链接:POJ 3805 Problem Description Numbers of black and white points are placed on a plane. Let's ima ...

  2. POJ 2464 Brownie Points II (树状数组,难题)

    题意:在平面直角坐标系中给你N个点,stan和ollie玩一个游戏,首先stan在竖直方向上画一条直线,该直线必须要过其中的某个点,然后ollie在水平方向上画一条直线,该直线的要求是要经过一个sta ...

  3. POJ - 2464 Brownie Points II 【树状数组 + 离散化】【好题】

    题目链接 http://poj.org/problem?id=2464 题意 在一个二维坐标系上 给出一些点 Stan 先画一条过一点的水平线 Odd 再画一条 过Stan那条水平线上的任一点的垂直线 ...

  4. POJ 2403 Hay Points

    Hay Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5735   Accepted: 3695 Descri ...

  5. hdu 1156 && poj 2464 Brownie Points II (BIT)

    2464 -- Brownie Points II Problem - 1156 hdu分类线段树的题.题意是,给出一堆点的位置,stan和ollie玩游戏,stan通过其中一个点画垂线,ollie通 ...

  6. 【POJ 1389】Area of Simple Polygons(线段树+扫描线,矩形并面积)

    离散化后,[1,10]=[1,3]+[6,10]就丢了[4,5]这一段了. 因为更新[3,6]时,它只更新到[3,3],[6,6]. 要么在相差大于1的两点间加入一个值,要么就让左右端点为l,r的线段 ...

  7. POJ 2464 Brownie Points II(树状数组)

    一开始还以为对于每根竖线,只要与过了任意一点的横线相交都可以呢,这样枚举两条线就要O(n^2),结果发现自己想多了... 其实是每个点画根竖线和横线就好,对于相同竖线统计(一直不包含线上点)右上左下总 ...

  8. POJ 2464 Brownie Points II --树状数组

    题意: 有点迷.有一些点,Stan先选择某个点,经过这个点画一条竖线,Ollie选择一个经过这条直接的点画一条横线.Stan选这两条直线分成的左下和右上部分的点,Ollie选左上和右下部分的点.Sta ...

  9. Poj 2403 Hay Points(Map)

    一.题目大意 实现一个工资计算系统.工资的计算规则是:首先,给定一些关键字和对应的价值,这个相对于字典.然后给出的是求职者的描述,如果这个描述中包含关键字则加上对应的价值,总得价值就是这个求职者的工资 ...

随机推荐

  1. mysql之多表查询

    今天在项目中遇到一个数据库查询的问题:三张表分别放置不同的东西:分享的音频相关数据.分享的文字图片说说.分享的主题相关数据.所有分享的东西都可看做新鲜事,现在要求从这三张表将相同的几个字段的数据全部查 ...

  2. linux set,env和export

    set,env和export这三个命令都可以用来显示shell变量 set 显示当前shell的变量,包括当前用户的变量 env 显示当前用户的变量 export 显示当前导出成用户变量的shell变 ...

  3. html 设置Select options值进行绑定

    <select id="cdms"> <option value="">请选择...</option> <option ...

  4. ExtJs gridPanel Column 时间格式化

    var panel = new Ext.container.Viewport({ items: { xtype: 'gridpanel', id: 'gridPanel', store: store, ...

  5. WinForm 控件库

    1:Telerik 介绍: Telerik 是保加利亚的一个软件公司,专注于微软.Net平台的表示层与内容管理控件.Telerik 提供高度稳定性和丰富性能的组件产品,并可应用在非常严格的环境中. 现 ...

  6. 慎用ReentrantLock

    前言: 代码简洁与性能高效无法两全其美,本文章专注于并发程序的性能,如果您追求代码简洁,本文章可能不太适合,本文章属于Java Concurrency in Practice读书笔记. 在java5中 ...

  7. 1588: [HNOI2002]营业额统计 - BZOJ

    Description营业额统计 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger拿出了公司的账本,账本上记录了公司成立以来每天 ...

  8. 汇编invoke和call的关系

    win32汇编里面,我们既可以用invoke也可以用call调用子程序/函数,不过invoke使用简单方便,所以绝大多数情况我们都用invoke. 但是很多人只是知道使用它,对它却不是很了解.我以前对 ...

  9. 关于ref与out的区别

    写在最前面 这几天一直在公司接受培训,都是一些基础的知识,同时也乘着这个机会巩固一下自己的基础,基础太重要了.前些时一直看的是多线程方面的知识,接下来我会写一些其他方面的知识,毕竟作为一个实习新人得和 ...

  10. Android支付接入(四):联通VAC计费

    原地址:http://blog.csdn.net/simdanfeg/article/details/9012031 注意事项: 1.联通支付是不需要自己标识软硬计费点的,当平台申请计费点的时候会提交 ...