P2735 Power Electric Fences

Title Description

In this problem, the grid point is a cross point of the ordinate are all integers.

To his captive cattle farmer John (Farmer John) built a triangular grid. He (0, 0) from the origin of a pull live wire connecting lattice points (n, m) (0 <= n <32000,0 <m <32000), and then connected to the grid point (p, 0) (p > 0), and finally back to square one.

Cattle can be placed on each grid point inside the grid (very lean beef) is not met in the case of the power grid. If a grid across the grid, cattle must not be placed on the grid (and perhaps there will be some gains Farmer John). So how many cows can be put into the grid Farmer John go?

Input Format

Only one line input file contains three space separated integer: n, m and p.

Output Format

The output file is only one line containing an integer number of cattle grid contains representatives can be specified.

Sample input and output

Input # 1
7 5 10
Output # 1
20

Description / Tips

Title Translation from NOCOW.

USACO Training Section 3.4

 

 

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
long long n,m,p;
long long read(){
	long long a=0,b=1;
	char ch=getchar();
	while((ch<48||ch>57)&&ch!='-'){
		ch=getchar();
	}
	if(ch=='-'){
		b=-1;
		ch=getchar();
	}
	while(ch<48||ch>57){
		ch=getchar();
	}
	while(ch>47&&ch<58){
		a=a*10+ch-48;
		ch=getchar();
	}
	return a*b;
}

long long gcd(long long x,long long y){
    return x% y == 0: gcd (y, x% y);
}
int main () {
	n=read(),m=read(),p=read();
    long long s=p*m/2;
    long long cnt=(gcd(n,m)+gcd(abs(n-p),m)+p)/2;
    long long s-years = cnt + 1;
    printf("%lld\n",ans);
    return 0;
}

  

ad:

Pick's Theorem to find out.

 

discoverer

Name: George Alexander Pique (1859 - 1943)

Full name: George Alexander Pick

Country: Austria

General

Pick's Theorem refers to a calculated matrix of vertices in the polygon area formula lattice points, the equation can be expressed as a 2S = 2a + b-2, where a represents the number of points inside the polygon, b represents the number of points on a polygon edge, S It represents the area of the polygon.

Theorem defined

a=39,b=14,s=45a=39,b=14,s=45

A graph paper, painted above aspect two sets of parallel lines , the distance between adjacent parallel lines are equal, so that the intersection of two sets of parallel lines, the so-called grid . If a grid point takes to do an origin O, as shown in FIG 1, taken through this grid point lateral and vertical two lines are made the abscissa axis and the ordinate axis OX OY, and taking the original square side length do units long, establish a coordinate system. Then the previously mentioned lattice point, obviously both horizontal and vertical coordinates of the points are integers. O in FIG. 1, P, Q, M, N are the lattice points. For this reason , we are called grid points the whole point .

A polygon vertices if all grid points, which is called the polygon grid polygon. Interestingly, this area of the lattice point of the polygon is calculated very convenient, as long as the number of bit pattern edge points on the number of number of points in the map and, can be calculated using the formula.

This formula is Pique (Pick) given in 1899, is known as "Pick's Theorem", which is a practical and interesting theorem.

Given vertex coordinates are integer points (lattice points or square) of simple polygons, Pick's theorem of the area S and the number of internal lattice points n, the relationship between the number of lattice points s of the edge:

(Where n denotes a polygon interior points, s represents the polygon boundary on the points , S represents the area of the polygon)

Derivation verification

Because all polygons can be simply cut into a triangle and other simple polygons. Consider a simple polygon P , and with P have a common side of the triangle T . If P meet pg formula, as long as proof P plus T a PT line with Pick formula (the I), and a triangle meet pg formula (II), can according to the mathematical induction, all formulas are simple polygons pg It was founded in.

Polygon

Let P and the common edge with a T c of lattice points.

P area:  the iP  +  bP / 2 -. 1

T area:  iT  +  bT / 2 -. 1

PT area:

(iT + iP + c - 2) + (bTc + 2 + bP - c) /2 - 1 = iPT + bPT/2 - 1

triangle

Proof of three parts: The following graphics demonstrate compliance with Pick's Theorem:

All parallel to the axis of the rectangle;

In two adjacent sides of the rectangle and a right triangle consisting of the diagonal;

All triangles (as they can be inscribed in a rectangle, the rectangle is divided into the original triangle and up to 3 points mentioned second right triangle).

rectangle

Provided rectangle R long sides have a short side m , n- lattice points:

AR = (m-1)(n-1)

iR = (m-2)(n-2)

bR = 2(m+n)-4

iR + bR/2 - 1 = (m-2)(n-2) + (m+n) - 2 - 1 = mn - (m + n) +1 = (m-1)(n-1)

Right triangle

Easy to see that two adjacent edges and diagonal two right triangle congruent composition, and I , B are equal. There is provided on the hypotenuse c lattice points.

b = m+n+c-3

i = ((m-2)(n-2) - c + 2)/2

i + b/2 - 1 = ((m-2)(n-2) - c + 2)/2 + (m+n+c-3)/2 - 1 = (m-2)(n-2)/2 + (m+n - 3)/2 = (m-1)(n-1)/2

General triangle

Front against the use of two polygons proof: Since rectangular in line with Pick's Theorem, right triangle in line with Pick's Theorem. And if to prove in front of P, T in line with Pique formula, P plus T is also in line with PT Pique formula. Because it may be decomposed into a rectangular triangle and up to three arbitrary right triangle. So apparently, only when any of this triangle is also consistent with Pick's Theorem, will make at the same time meet the right triangle, the rectangle is also in line.

 

Above from 360 Wikipedia .

If wrong, is not responsible.

Guess you like

Origin www.cnblogs.com/xiongchongwen/p/11605611.html