首页 > 其他分享 >Electric Fence

Electric Fence

时间:2023-08-12 19:35:33浏览次数:31  
标签:Electric fence int 电网 格点 lattice Fence cows

描述

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

题意如下

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

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

牛可以在不碰到电网的情况下被放到电网内部的每一个格点上(十分瘦的牛)。如果一个格点碰到了电网,牛绝对不可以被放到该格点之上(或许Farmer John会有一些收获)。那么有多少头牛可以被放到农夫约翰的电网中去呢?
题解

因为边界上的点不能放,所以答案=三角形内所有点-边界上的点

三角形内所有点可以通过 皮克定理:

给定顶点坐标均是整点(或正方形格点)的简单多边形,皮克定理说明了其面积S和内部格点数目n、多边形边界上的格点数目s的关系:

边界上的点可以通过最大公约数算出

举例(0,0)到(n,m)中,一共有gcd(n,m)+1个整点在上面(包含两端)

原理就是假如x可以同时整除n和m的话,(n/x,m/x)必定是整点

所以把三条边全算出来就行了,顶点特殊处理一下

#include <bits/stdc++.h>
using namespace std;
int gcd(int x,int y)
{
    if(y==0) return x;
    return gcd(y,x%y);
}
signed main()
{
    int n,m,p;
    cin>>n>>m>>p;
    cout<<(m*p)/2-(gcd(n,m)+gcd(abs(n-p),m)+p)/2+1;
}

 

标签:Electric,fence,int,电网,格点,lattice,Fence,cows
From: https://www.cnblogs.com/sleepaday/p/17625316.html

相关文章

  • pacemaker使用fence_sbd
    AdministrativeProceduresforRHELHighAvailabilityclusters-EnablingsbdfencinginRHEL7and8-RedHatCustomerPortal启动watchdog每个server执行modprobesoftdogmodprobesoftdogcat/etc/sysconfig/modules/softdog.modulesmodprobesoftdogchmod7......
  • Painting the Fence 题解
    题目传送门一道枚举题。我们可以直接枚举那\(2\)个去掉的粉刷匠。先统计一下每个栅栏会被多少个粉刷匠刷到,然后枚举第一个被去掉的粉刷匠,然后计算剩下的粉刷匠会将每个栅栏刷到多少次,我们只需要看只能被刷\(1\)次的栅栏就行了。接着处理一个前缀和数组,记录前\(i\)个栅栏......
  • ZB5AA26 Schneider Electric 芯脉芯城
    ZB5AA26是一个产品型号,通常用于指示灯或按钮开关。以下是关于ZB5AA26的一些常见参数:封装类型:ZB5AA26采用的是标准的按钮开关封装。动作类型:ZB5AA26是一个单极单刀按钮开关,即具有一个触点和一个开关位置。额定电压:ZB5AA26的额定电压通常为24V,适用于直流或交流电源。额定电流:ZB5AA26......
  • Linux mem 2.8 Kfence 详解【转】
    转自:https://pwl999.blog.csdn.net/article/details/1244949581.原理介绍Kfence(KernelElectricFence)是Linux内核引入的一种低开销的内存错误检测机制,因为是低开销的所以它可以在运行的生产环境中开启,同样由于是低开销所以它的功能相比较KASAN会偏弱。Kfence的基本原......
  • Best Cow Fences(前缀和+特殊二分)
    之前的二分大多数都是整数类型的,今天又学到一种新型的二分,浮点数的二分,浮点数的二分可太巧妙了.且听我细细分说::OpenJudge-2018:BestCowFences#include<bits/stdc++.h>usingnamespacestd;constintN=1e5+10;intn,k;doublea[N],s[N],l,r;boolcheck(doubleu)......
  • POJ2117 Electricity 题解 tarjan点双连通分量 割点
    题目链接:http://poj.org/problem?id=2117题目大意:给定一个由\(n\)个点\(m\)解题思路:tarjan,判断\(u\)的子节点有几个\(v\)满足\(low[v]\gedfn[u]\)就是答案,但是同时如果\(u\)不是这个dfs树的根节点,个数还要加\(1\)。示例程序1(C++11,POJ不支持):#include<bits/stdc++.h>......
  • POJ2117 Electricity 题解 tarjan点双连通分量 割点
    题目链接:http://poj.org/problem?id=2117题目大意:给定一个由\(n\)个点\(m\)条边构成的无向图,请你求出该图删除一个点之后,连通块最多有多少。解题思路:tarjan,判断\(u\)的子节点有几个\(v\)满足\(low[v]\gedfn[u]\)就是答案,但是同时如果\(u\)不是这个dfs树的根节......
  • 【每日一题】Problem 363B. Fence
    原题解决思路求k个木板的最小高度和,因为所有木板的高度和不超过1e9,因此计算出到当前木板j的总高度-前j-k模板的总高度并求得最小数即可#include<bits/stdc++.h>intmain(){intn,k;std::cin>>n>>k;std::vector<int>vec(n+1,0);for(in......
  • 4、题目:Creativity in Electrical Engineering Degree Programs: Where Is the Conten
    期刊信息(1)作者:Adams,Scott(2)期刊:IEEETransactionsonEducation,2019/11,62-4:288-296(3)DOI:10.1109/TE.2019.2912834(4)ISSN:0018-9359(5)IF:2.74(Q2)研究背景先前的研究表明,工程教学大纲中包含创造力培养,课堂活动通常受到限制。学生可能认为教育工作者不重视......
  • C++并发之fence
    intx=0;inty=0;intr0,r1;//cpu1voidf1(){x=1;std::atomic_thread_fence(std::memory_order_acquire);r0=y;}//cpu2voidf2(){y=1;std::atomic_thread_fence(std::memory_order_acquire);r1=x;} fence......