主要利用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的更多相关文章

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

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5861   Accepted: 2612 Description ...

  2. Area POJ - 1265 -皮克定理-叉积

    Area POJ - 1265 皮克定理是指一个计算点阵中顶点在格点上的多边形面积公式,该公式可以表示为2S=2a+b-2, 其中a表示多边形内部的点数,b表示多边形边界上的点数,S表示多边形的面积. ...

  3. POJ 1265 Area (Pick定理 & 多边形面积)

    题目链接:POJ 1265 Problem Description Being well known for its highly innovative products, Merck would d ...

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

    链接:http://poj.org/problem?id=1265 Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:  ...

  5. poj 1265 Area( pick 定理 )

    题目:http://poj.org/problem?id=1265 题意:已知机器人行走步数及每一步的坐标   变化量 ,求机器人所走路径围成的多边形的面积.多边形边上和内部的点的数量. 思路:1.以 ...

  6. poj 1265 Area【计算几何:叉积计算多边形面积+pick定理计算多边形内点数+计算多边形边上点数】

    题目:http://poj.org/problem?id=1265 Sample Input 2 4 1 0 0 1 -1 0 0 -1 7 5 0 1 3 -2 2 -1 0 0 -3 -3 1 0 ...

  7. POJ 1265 Area POJ 2954 Triangle Pick定理

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5227   Accepted: 2342 Description ...

  8. poj 1265&&poj 2954(Pick定理)

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5811   Accepted: 2589 Description ...

  9. POJ 1265 Area

    有一种定理,叫毕克定理....                             Area Time Limit: 1000MS   Memory Limit: 10000K Total Sub ...

  10. poj 1265 Area(Pick定理)

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5666   Accepted: 2533 Description ...

随机推荐

  1. 微信图片不可显示java解决方法

    先看知乎:https://www.zhihu.com/question/35044484 场景: 微信上传了图片素材,返回了图片url,然后不能在img标签中正常显示. 原因是微信做了图片防盗连接. ...

  2. C# 对象克隆,DataTable转LIST

    public class ConvertHelper<T> where T : new() { private static string module = "ConvertHe ...

  3. Android java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader......couldn't find "libweibosdkcore.so

    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/ ...

  4. Hive2.1.1集群搭建

    软件环境: linux系统: CentOS6.7 Hadoop版本: 2.6.5 zookeeper版本: 3.4.8 主机配置: 一共m1, m2, m3这五部机, 每部主机的用户名都为centos ...

  5. C# 获取所有网卡信息

    private void Form1_Load(object sender, EventArgs e) { //获取说有网卡信息 NetworkInterface[] nics = NetworkIn ...

  6. Embedded之Makefile

    1 Header files The header files are empty, so you can create them with touch: $ touch a.h $ touch b. ...

  7. 黑客常用dos命令

    http://blog.csdn.net/CSDN___LYY/article/details/77802438

  8. 图像连通域检测的2路算法Code

    本文算法描述参考链接:http://blog.csdn.net/icvpr/article/details/10259577 两遍扫描法: (1)第一次扫描: 访问当前像素B(x,y),如果B(x,y ...

  9. efcore 控制台迁移架构

    添加 nuget 包: Microsoft.EntityFrameworkCore.Design Microsoft.EntityFrameworkCore.SqlServer Microsoft.E ...

  10. TextInputLayout使用时各个地方的字体颜色

    我们现在在做Android端的输入框时,要具备如下功能: 默认提示获取焦点时提示上移至输入框顶部获取焦点时输入框有提示错误时增加错误提示直接上图: 默认情况: 获取焦点时: 开始输入文字时: 有错误时 ...