Triangle - POJ 2954(求三角形内的格子点的个数)
Pick公式:平面上以格子点为顶点的简单多边形的面积=边上的点数/2+内部的点数+1。
代码如下:
----------------------------------------------------------------------------------------------------------------------------
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std; const int MAXN = ;
const double EPS = 1e-; struct point
{
int x, y;
}p[MAXN]; int GCD(int m, int n)
{
if(!m || !n)
return m+n;
return GCD(n, m%n);
} int main()
{
while()
{
int ok=; for(int i=; i<; i++)
{
scanf("%d%d", &p[i].x, &p[i].y);
if(p[i].x || p[i].y)
ok = ;
} if(!ok)break;
p[] = p[]; int cnt=, area=; for(int i=; i<; i++)
{
cnt += GCD(abs(p[i].x-p[i+].x), abs(p[i].y-p[i+].y));
area += p[i].x*p[i+].y - p[i].y*p[i+].x;
}
if(area < )area = -area; printf("%d\n", (area-cnt)/+);
} return ;
}
Triangle - POJ 2954(求三角形内的格子点的个数)的更多相关文章
- POJ 1265 Area POJ 2954 Triangle Pick定理
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5227 Accepted: 2342 Description ...
- poj 2954 Triangle 三角形内的整点数
poj 2954 Triangle 题意 给出一个三角形的三个点,问三角形内部有多少个整点. 解法 pick's law 一个多边形如果每个顶点都由整点构成,该多边形的面积为\(S\),该多边形边上的 ...
- UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)
Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...
- poj 1090:The Circumference of the Circle(计算几何,求三角形外心)
The Circumference of the Circle Time Limit: 2 Seconds Memory Limit: 65536 KB To calculate the c ...
- hdu 2105:The Center of Gravity(计算几何,求三角形重心)
The Center of Gravity Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- poj 1265&&poj 2954(Pick定理)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5811 Accepted: 2589 Description ...
- TZOJ 2519 Regetni(N个点求三角形面积为整数总数)
描述 Background Hello Earthling. We're from the planet Regetni and need your help to make lots of mone ...
- HDU 2036 叉乘求三角形面积
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...
- hrbustoj 1142:围困(计算几何基础题,判断点是否在三角形内)
围困 Time Limit: 1000 MS Memory Limit: 65536 K Total Submit: 360(138 users) Total Accepted: 157(12 ...
随机推荐
- webbench
Webbench Webbench是一个在linux下使用的非常简单的网站压测工具.它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的性能,最多可以模拟3万个并发连接去测 ...
- Python3 模块
为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文件包含的代码就相对较少,很多编程语言都采用这种组织代码的方式.在Python中,一个.py文件就称之为一个模块(Module ...
- ubuntu 下的 ftp (gftp)
功能和 windows 下的 ftp 一样 gftp安装方法apt-get install gftp启动方法:gfpt
- HTML css面试题
1.对WEB标准以及W3C的理解与认识 标签闭合.标签小写.不乱嵌套.提高搜索机器人搜索几率.使用外链css和js脚本.结构行为表现的分离.文件下载与页面速度更快.内容能被更多的用户所访问.内容能被更 ...
- mysql扩展库操作mysql数据库
环境搭建 启用mysql扩展库,在php.ini文件中去配置mysql扩展库 extension=php_mysql.dll 查询数据库 1.建库建表 //建库testcreate database ...
- eval 如何定义函数
eval(compile('''def fun(): print 'bbb' ''', '<string>', 'exec')) fun()
- 如何利用SecureCRT连接Ubuntu12.0.4
环境描述:虚拟机网络选择NAT连接方式,Ubuntu的版本是Ubuntu12.0.4 1. 先做一个测试,假设现在系统还没有装ssh,用secureCRT连接Ubuntu是出现下面的界面. 实际上,这 ...
- windows 远程桌面连接ubuntu xrdp 只看到墙纸其他什么都没有
用 windows 的 mstsc 连接 ubuntu 的 xrdp 时,进入后只看到墙纸,其他什么都没有,鼠标指针也不见,输入按键都无反应. 原来 Ubuntu 启动了 3d 桌面,导致 xrdp ...
- Discuz! 7.2 SQL注入exp
已经有人写出一些工具了,但是感觉不怎么好用,就自己写了个. 参数:1.可直接getshell2.爆管理账号密码3.爆表前缀如果表前缀不是默认的cdb_ 只需更改代码中的 $table即可,方便快捷. ...
- Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderListener(Maven工程)
Eclipse中tomcat部署工程启动后报错: 严重: Error configuring application listener of class org.springframework.web ...