洛谷 P2735 电网 Electric Fences

编程入门 行业动态 更新时间:2024-10-24 01:48:55

洛谷 P2735 <a href=https://www.elefans.com/category/jswz/34/1759043.html style=电网 Electric Fences"/>

洛谷 P2735 电网 Electric Fences

洛谷 P2735 电网 Electric Fences


题目

题目描述

在本题中,格点是指横纵坐标皆为整数的点。

为了圈养他的牛,农夫约翰(Farmer John)建造了一个三角形的电网。他从原点(0,0)牵出一根通电的电线,连接格点(n,m)(0<=n<32000,0

7 5 10

输出样例#1:

20

题解

数学知识的应用

tip:毕克定理公式: S=(2N+L-2)/2

其中,S是格点多边形的面积,N是区域内部的格点数,L是区域边界上的格点数。


代码

#include<cstdio>
#include<cmath>
using namespace std;int n,m,p,L,ans;
double a,b,c,w,S;int gcd(int x,int y)
{if (x==0) return y;else return gcd(y%x,x);
}int abs(int x)
{if (x<0) return -x; else return x;
}int main()
{scanf("%d%d%d",&n,&m,&p);L=gcd(n,m)+gcd(abs(p-n),m)+p;S=p*m;ans=trunc(S+2-L)/2;printf("%d",ans);return 0;
}

“`

更多推荐

洛谷 P2735 电网 Electric Fences

本文发布于:2024-03-07 21:06:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1718912.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电网   洛谷   Electric   Fences

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!