Electric Fence
Don Piele

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?

PROGRAM NAME: fence9

INPUT FORMAT

The single input line contains three space-separated integers that denote n, m, and p.

SAMPLE INPUT (file fence9.in)

7 5 10

OUTPUT FORMAT

A single line with a single integer that represents the number of cows the specified fence can hold.

SAMPLE OUTPUT (file fence9.out)

20
——————————————————————————————————
皮克定理,在格点多边形S=a+b/2-1 其中a是多边形内部的点数,b是多边形边上的点数
先mark,考完期末之后回来看证明 2017.1.2
 /*
ID: ivorysi
PROG: fence9
LANG: C++
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <string.h>
#define siji(i,x,y) for(int i=(x);i<=(y);++i)
#define gongzi(j,x,y) for(int j=(x);j>=(y);--j)
#define xiaosiji(i,x,y) for(int i=(x);i<(y);++i)
#define sigongzi(j,x,y) for(int j=(x);j>(y);--j)
#define inf 0x3f3f3f3f
#define MAXN 400005
#define ivorysi
#define mo 97797977
#define ha 974711
#define ba 47
#define fi first
#define se second
#define pii pair<int,int>
using namespace std;
typedef long long ll;
int n,m,p;
int s,k;
int gcd(int a,int b) {return b== ? a : gcd(b,a%b);}
void solve() {
scanf("%d%d%d",&n,&m,&p);
s=p*m;
k=k+gcd(m,n)-;
k=k+gcd(abs(n-p),m)-;
k=k++p;
int ans=(s-k+)/;
printf("%d\n",ans);
}
int main(int argc, char const *argv[])
{
#ifdef ivorysi
freopen("fence9.in","r",stdin);
freopen("fence9.out","w",stdout);
#else
freopen("f1.in","r",stdin);
#endif
solve();
}
 

USACO 3.4 Electric Fence的更多相关文章

  1. USACO 3.4 Electric Fence 皮克定理

    题意:在方格纸上画出一个三角形,求三角形里面包含的格点的数目 因为其中一条边就是X轴,一开始想的是算出两条边对应的数学函数,然后枚举x坐标值求解.但其实不用那么麻烦. 皮克定理:给定顶点坐标均是整点( ...

  2. 内存调试工具Electric Fence

    源码下载地址 注:官方地址下载不了,可能不再维护了,此是一个老项目 efence中相关环境变量控制: 302 /* 303 * See if the user wants to allow mallo ...

  3. 【TOJ 5103】Electric Fence(皮克定理)

    描述 In this problem, `lattice points' in the plane are points with integer coordinates. In order to c ...

  4. USACO 6.4 Electric Fences

    Electric FencesKolstad & Schrijvers Farmer John has decided to construct electric fences. He has ...

  5. [usaco] 2008 Dec Largetst Fence 最大的围栏 2 || dp

    原网站大概已经上不了了-- 题目大意: 求出平面上n个点组成的一个包含顶点数最多的凸多边形.n<=250. 考虑我们每次枚举凸包的左下角为谁(参考Graham求凸包时的左下角),然后像Graha ...

  6. USACO 2006 November Gold Fence Repair /// 贪心(有意思)(优先队列) oj23940

    题目大意: 输入N ( 1 ≤ N ≤ 20,000 ) :将一块木板分为n块 每次切割木板的开销为这块木板的长度,即将长度为21的木板分为13和8,则开销为21 接下来n行描述每块木板要求的长度Li ...

  7. usaco training 3.4.3 fence9 题解

    Electric Fence题解 Don Piele In this problem, `lattice points' in the plane are points with integer co ...

  8. USACO 完结的一些感想

    其实日期没有那么近啦……只是我偶尔还点进去造成的,导致我没有每一章刷完的纪念日了 但是全刷完是今天啦 讲真,题很锻炼思维能力,USACO保持着一贯猎奇的题目描述,以及尽量不用高级算法就完成的题解……例 ...

  9. USACO Training刷题记录 By cellur925

    Section 1.1 Your Ride Is Here 貌似没啥可说 Greedy Gift Givers 上来就想stl map映射,有两个坑:如果送给别人的人数为0,那么需要特判一下,防止整数 ...

随机推荐

  1. 让大蛇(Python)帮你找工作

    前段时间用Python实现了一个网络爬虫(让大蛇(Python)帮你找工作),效率总体还可以,但是缺点就是每次都需要手动的去触发,于是打算对该爬虫加上Timer,经过网上一番搜索以及API的查询,发现 ...

  2. Linux 系统命令总结

    自己收集到的Linux系统命令大全! 1,查看apache2的连接状态: netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S ...

  3. TeamCity vs Jenkins: Which is the Better Continuous Integration (CI) Server for .NET Software Development?

    原文:http://www.excella.com/insights/teamcity-vs-jenkins-better-continuous-integration-server So, you’ ...

  4. 【学习笔记】《JavaScript DOM 编程艺术》 ——总结

    一.要点阐述 1,程序设计语言分为解释型和编译型两大类,JS属于解释型,在Web浏览器中一边解释一边执行. 2,"//"注释单行,"/*...*/"注释多行.反 ...

  5. Lambda表达式的几种使用方式

    Lambda 的表达式的编写格式如下: x=> x * 1.5 当中 “ => ” 是 Lambda 表达式的操作符,在左边用作定义一个参数列表,右边可以操作这些参数. 例一, 先把 in ...

  6. D0

    刚到长乐就被机房里众大神的气场给压倒了 orz....... 然后默默的感觉到自己貌似已经有一个星期没有打题了...就各种忧伤.... 还是说一下今天的计划吧 嗯傍晚5.30-6.00 &&a ...

  7. SQLSERVER利用FOR XML PATH实现分组拼接字符串

    首先看一下数据结构表 IF(OBJECT_ID('tempdb..#tProduct')IS NOT NULL) DROP TABLE #tProduct SELECT * INTO #tProduc ...

  8. vm_write

    #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types. ...

  9. [google面试CTCI] 2-3 只给定链表中间节点指针,如何删除中间节点?

    [链表] Q:Implement an algorithm to delete a node in the middle of a single linked list, given only acc ...

  10. [转]PT_DENY_ATTACH

    PT_DENY_ATTACH[1] is an Apple-specific constant that can prevent debuggers (gdb, DTrace, etc.) from ...