POJ 1265

主要利用PICK定理与边点数上的GCD的关系求解。

三角形一条边上的所有整数点(包括顶点)可以首先将这条边移到(0, 0)->(x, y)。这时,(x/gcd(x, y), y/gcd(x, y))肯定在这条边上,并且是整数点,其余所有整数点的可以表示为k(x/gcd(x, y), y/gcd(x, y))。所以所有的整数点个数为gcd(x, y) + 1。即:

b = gcd(x, y) + 1

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
const int MAX=110;
struct point {
	double x,y;
}p[MAX];
int n;

int gcd(int x,int y){
	while(y){
		int tmp=y;
        y = x % y;
        x = tmp;
    }
    return x;
}

int main(){
	int t; int cas=0;
	cin>>t;
	while(t--){
		cas++;
		cin>>n;
		double tx,ty;
		for(int i=0;i<n;i++){
			cin>>tx>>ty;
			if(i==0){
				p[i].x=tx; p[i].y=ty;
			}
			else{
				p[i].x=p[i-1].x+tx;
				p[i].y=p[i-1].y+ty;
			}
		}
		p[n]=p[0];
		double ans=0;
		for(int i=0;i<n;i++)
		ans+=(p[i].x*p[i+1].y-p[i].y*p[i+1].x);
		ans=(ans)/2;
		int edg=0,in=0;
		for(int i=0;i<n;i++)
		edg+=gcd(abs((int)(p[i].x-p[i+1].x)),abs(int(p[i].y-p[i+1].y)));
		in=(((ans+1)*2-edg)/2);
		printf("Scenario #%d:\n",cas);
		printf("%d %d %.1lf\n",in,edg,ans);
		printf("\n");
	}
	return 0;
}

  

POJ 1265,布布扣,bubuko.com

时间: 2024-10-13 12:37:47

POJ 1265的相关文章

poj 1265 Area (Pick定理+求面积)

链接:http://poj.org/problem?id=1265 Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4969   Accepted: 2231 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionag

POJ 1265 Area

Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4713   Accepted: 2129 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionage. To protect its brand-new resear

poj 1265 Area 面积+多边形内点数

Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5861   Accepted: 2612 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionage. To protect its brand-new resear

poj 1265 Area(pick 定理)

链接:poj 1265 题意:从原点出发.给出一些dx,dy移动增量,终于形成一个多边形, 求多边形内部的格点数目,边上的格点数目 .以及面积. 补充知识: 1.以格子点为顶点的线段.覆盖的点的个数为gcd(|dx|,|dy|).当中,|dx|,|dy|分别为线段横向增量和纵向增量. 2.Pick定理:设平面上以格子点为顶点的多边形的内部点个数为a.边上点个数为b.面积为S,则 S = a + b/2 -1. 3.随意一个多边形的面积等于以多边形边上的某点为固定点.按顺序求其余点相邻两个点与该点

POJ 1265:Area

Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4725   Accepted: 2135 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionage. To protect its brand-new resear

POJ 1265 计算几何 多边形面积 内部格点数 边上格点数

链接: http://poj.org/problem?id=1265 题意: 给你一个多边形,求它的面积,内部格点数目,边上格点数目 题解: pick公式: 给定顶点坐标均是整数点的简单多边形,有 面积=内部格点数目+边上格点数目/2+1 边界上的格点数: 把每条边当做左开右闭的区间以避免重复,一条左开右闭的线段(x1,y1)->(x2,y2)上的格点数为: gcd(x2-x1,y2-y1). 代码: 1 #include <map> 2 #include <set> 3 #

POJ 1265 Area POJ 2954 Triangle Pick定理

Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5227   Accepted: 2342 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionage. To protect its brand-new resear

poj 1265 Area(Pick定理)

Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5666   Accepted: 2533 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionage. To protect its brand-new resear

POJ 1265 Area Pick公式

题目大意:给出一个多边形的轮廓(以边的向量形式给出),求:1.有多少个整点在这个图形里面,2.有多少个点在图形内部,3.图形的面积是多少. 思路:首先明确Pick公式: 公式意义并不是让我们求出这个多边形的面积是多大,一是因为面积没必要用Pick公式求,二是没法求出多边形中间有多少整点.但是面积可以用叉积来求,多边形边上的整点可以用gcd来求,这样经过稍微的变形,就可以求解多边形中间有多少个整点了. CODE(c++AC,g++WA,求高人指点): #include <cstdio> #inc