Hust oj 1056 Electric Fence(皮克定理)
来源:互联网 发布:巫师3正版优化 编辑:程序博客网 时间:2024/06/10 05:43
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<32000, 0<m<32000), then to a lattice point on the positive x axis [p,0] (p>0), 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?
InputFirst line contains an integer n: the number of test case.
Then n lines follow, each line contains three space-separated integers that denote n, m, and p.
OutputA single line with a single integer for each test case that represents the number of cows the specified fence can hold.
Sample Input27 5 10
1 1 2Sample Output20
0
这题我会了皮克定理才会的,不会之前一点思路没有
一个多边形的顶点如果全是格点,这多边形就叫做格点多边形。有趣的是,这种格点多边形的面积计算起来很方便,只要数一下图形边线上的点的数目及图内的点的数目,就可用公式算出。
这个公式是皮克(Pick)在1899年给出的,被称为“皮克定理”,这是一个实用而有趣的定理。给定顶点坐标均是整点(或正方形格点)的简单多边形,a=39,b=14,s=45,皮克定理说明了其面积S和内部格点数目a、边上格点数目b的关系:S=a+b÷2-1。(其中a表示多边形内部的点数,b表示多边形边界上的点数,S表示多边形的面积)
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cstdlib>#include<cmath>using namespace std;int gcd(int x,int y){ if(x < y) { int temp = x; x = y; y = temp; } while(y) { int temp = x % y; x = y; y = temp; } return x;}int n,m,p;int t;int main(){ scanf("%d",&t); while(t--) { scanf("%d %d %d",&n,&m,&p); int sum; int gcd1 = gcd(n,m); int gcd2 = gcd(fabs(p-n),m); sum = gcd1 + gcd2 + p; int area = p * m / 2; printf("%d\n",area + 1 -(sum/2)); }}
- Hust oj 1056 Electric Fence(皮克定理)
- usaco 3.4 Electric Fence 皮克定理
- USACO Section 3.4 Electric Fence - Pick定理
- Electric Fences_usaco3.4_皮克定理
- Electric Fence
- Electric Fence
- Electric Fence
- USACO-Section 3.4 Electric Fence (模拟)
- USACO 3.4 Electric Fences电网 (数学.皮克定理)
- NOJ 1434 Fence (皮克定理)
- Section 3.4 Electric Fence
- usaco Electric Fence
- USACO 3.4 Electric Fence
- usaco Electric Fence
- usaco3.4.2 Electric Fence
- [USACO3.4.2]Electric Fence
- Hust oj 2084(大数)
- 内存调试工具Electric Fence
- redis实现主从复制和高可用(主从切换)
- 【IOS学习】 ios htttp网络请求cookie的读取与写入(NSHTTPCookieStorage)
- 存储器的保护
- 平衡二叉树
- 设计响应式导航菜单的五大法则
- Hust oj 1056 Electric Fence(皮克定理)
- 错误: (串列)对象不能强制改变成'double'解决办法
- LaTeX制作简历及eps格式图片转换
- 用Activity实现类似AlertDialog的效果
- 映客APP体验报告
- php设计模式之观察者模式
- Git入门(8)-删除文件
- PendingIntent的内部机制
- Java虚拟机知识整理——类加载的过程