描述

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 ;
}

最新文章

  1. Web jquery表格组件 JQGrid 的使用 - 从入门到精通 开篇及索引
  2. iOS 面试题搜集
  3. 一般企业网站,电商可以完全可以水平拓展的lanmp系统架构
  4. javascript笔记图
  5. putty保持不掉线
  6. [MetaHook] R_SparkShower
  7. Android之自定义生成彩色二维码
  8. 1305: [CQOI2009]dance跳舞 - BZOJ
  9. jquery知识 属性 css
  10. DAL与数据库类型的对应关系
  11. poj 1273 Drainage Ditches (网络流 最大流)
  12. Android之Activity生命周期简介
  13. GridView and DropDownList
  14. 写一个Redis封装类
  15. Scala关于软件的安装
  16. 如何结合场景利用block进行回调
  17. Shell中$X的含义
  18. 【Unity3D】 Unity Chan项目分享
  19. Python 小试牛刀,Django详细解读,让你更快的掌握它!!!
  20. iOS----------计算一段代码执行时间

热门文章

  1. python中操作列表
  2. javascript小数相减出现一长串的小数位数
  3. HashMap和Hashtable存放null
  4. C++里创建 Trie字典树(中文词典)(二)(插入、查找、导入、导出)
  5. 运行jsp时,报错404
  6. Spring Cloud Ribbon负载均衡配置类放在Spring boot主类同级增加Exclude过滤后报Field config in com.cloud.web.controller.RibbonConfiguration required a bean of type &#39;com.netflix.client.config.IClientConfig&#39; that could not b
  7. 前端之CSS——属性和定位
  8. angular2-生命周期钩子函数
  9. join......on 后面的and 和where的区别
  10. 05_Jedis操作Redis