【TOJ 5103】Electric Fence(皮克定理)
描述
In this problem, `lattice points' in the plane are points with integer coordinates.
In order to contain his cows, Farmer John constructs a triangular electric fence by stringing a "hot" wire from the origin (0,0) to a lattice point [n,m] (0<=;n<32,000, 0<m<32,000), then to a lattice point on the positive x axis [p,0] (0<p<32,000), and then back to the origin (0,0).
A cow can be placed at each lattice point within the fence without touching the fence (very thin cows). Cows can not be placed on lattice points that the fence touches. How many cows can a given fence hold?
输入
The single input line contains three space-separated integers that denote n, m, and p.
输出
A single line with a single integer that represents the number of cows the specified fence can hold.
样例输入
7 5 10
样例输出
20
题意:
有一个位于第一象限的三角形,其中一个点为原点(0,0),另外一个点位于x轴上的(p,0),剩下一个点位于(n,m)。
求这个三角形内的格点有多少个(不包括三角形的边界)
思路:
(1) 使用皮克定理可以轻松解决!
皮克定理是指一个计算点阵中顶点在格点上的多边形面积公式,该公式可以表示为2S=2a+b-2,其中a表示多边形内部的点数,b表示多边形边界上的点数,S表示多边形的面积。
(2) gcd(线段的铅锤高,水平宽) = 线段的格点数-1
#include<bits/stdc++.h>
using namespace std;
//pick:2s=2a+b-2;
//a内部点 b边界点 s多边形面积
int main()
{
int n,m,p,b1,b2,a;
double s;
cin>>n>>m>>p;
s=p*m*1.0/;
if(n!=)
b1=__gcd(n,m)-; //线段上除2个端点外的格点数
else if(n==)b1=m-; if(p!=n)
b2=__gcd(abs(n-p),m)-;
else if(p==n)b2=m-; a=s-(b1+b2+p+)/+;
cout<<a<<endl;
return ;
}
【TOJ 5103】Electric Fence(皮克定理)的更多相关文章
- USACO 3.4 Electric Fence 皮克定理
题意:在方格纸上画出一个三角形,求三角形里面包含的格点的数目 因为其中一条边就是X轴,一开始想的是算出两条边对应的数学函数,然后枚举x坐标值求解.但其实不用那么麻烦. 皮克定理:给定顶点坐标均是整点( ...
- 洛谷 P2735 电网 Electric Fences Label:计算几何--皮克定理
题目描述 在本题中,格点是指横纵坐标皆为整数的点. 为了圈养他的牛,农夫约翰(Farmer John)建造了一个三角形的电网.他从原点(0,0)牵出一根通电的电线,连接格点(n,m)(0<=n& ...
- USACO 3.4 Electric Fence
Electric FenceDon Piele In this problem, `lattice points' in the plane are points with integer coord ...
- 内存调试工具Electric Fence
源码下载地址 注:官方地址下载不了,可能不再维护了,此是一个老项目 efence中相关环境变量控制: 302 /* 303 * See if the user wants to allow mallo ...
- poj1265&&2954 [皮克定理 格点多边形]【学习笔记】
Q:皮克定理这种一句话的东西为什么还要写学习笔记啊? A:多好玩啊... PS:除了蓝色字体之外都是废话啊... Part I 1.顶点全在格点上的多边形叫做格点多边形(坐标全是整数) 2.维基百科 ...
- Area POJ - 1265 -皮克定理-叉积
Area POJ - 1265 皮克定理是指一个计算点阵中顶点在格点上的多边形面积公式,该公式可以表示为2S=2a+b-2, 其中a表示多边形内部的点数,b表示多边形边界上的点数,S表示多边形的面积. ...
- Gym 101873G - Water Testing - [皮克定理]
题目链接:http://codeforces.com/gym/101873/problem/G 题意: 在点阵上,给出 $N$ 个点的坐标(全部都是在格点上),将它们按顺序连接可以构成一个多边形,求该 ...
- Area---poj1265(皮克定理+多边形求面积)
题目链接:http://poj.org/problem?id=1265 题意是:有一个机器人在矩形网格中行走,起始点是(0,0),每次移动(dx,dy)的偏移量,已知,机器人走的图形是一个多边形,求这 ...
- 【hdu1705】Count the grid(皮克定理)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1705 [题意] 给出平面上三个点坐标,求围成的三角形内部的点数 做这道题需要先了解下皮克定理. 百度百科: ...
随机推荐
- [转]scp命令学习
原博客地址http://www.cnblogs.com/peida/archive/2013/03/15/2960802.html scp是secure copy的简写,用于在Linux下进行远程拷贝 ...
- Python 动态加载 Extension Manager Classes
看着看着发现了一个库:stevedore(http://stevedore.readthedocs.org/en/latest/managers.html),但是感觉文档做得不行啊,都没个tutori ...
- Dozer 实现对象间属性复制
使用场景:两个领域之间对象转换. 比如:在系统分层解耦过程中, 对外facade接口,一般使用VO对象,而内core业务逻辑层或者数据层通常使用Entity实体. VO对象 package com.m ...
- TextView来实现跑马灯的效果
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- Java实现队列结构的详细代码
一.什么是队列结构 一种线性结构,具有特殊的运算法则[只能在一端(队头)删除,在另一端(队尾)插入]. 分类: 顺序队列结构 链式队列结构 基本操作: 入队列 出队列 二.准备数据 static fi ...
- select * from pet where species regexp '^c';
select * from pet where species regexp '^c';
- React总结和遇到的坑
一.react项目 前端react后端node:https://github.com/GainLoss/react-juejin 前端react后端Pyton:https://github.com/G ...
- 分享一个settings.xml
<?xml version="1.0" encoding="UTF-8"?> <settings> <localRepositor ...
- flume-ng 自定义sink消费flume source
如何从一个已经存在的Flume source消费数据 1.下载flume wget http://www.apache.org/dist/flume/stable/apache-flume-1.5.2 ...
- URI和URL有什么区别
URI 是从虚拟根路径开始的URL是整个链接如URL http://zhidao.baidu.com/question/68016373.html URI 是/question/68016373.ht ...