USACO 3.4 Electric Fence
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的更多相关文章
- USACO 3.4 Electric Fence 皮克定理
题意:在方格纸上画出一个三角形,求三角形里面包含的格点的数目 因为其中一条边就是X轴,一开始想的是算出两条边对应的数学函数,然后枚举x坐标值求解.但其实不用那么麻烦. 皮克定理:给定顶点坐标均是整点( ...
- 内存调试工具Electric Fence
源码下载地址 注:官方地址下载不了,可能不再维护了,此是一个老项目 efence中相关环境变量控制: 302 /* 303 * See if the user wants to allow mallo ...
- 【TOJ 5103】Electric Fence(皮克定理)
描述 In this problem, `lattice points' in the plane are points with integer coordinates. In order to c ...
- USACO 6.4 Electric Fences
Electric FencesKolstad & Schrijvers Farmer John has decided to construct electric fences. He has ...
- [usaco] 2008 Dec Largetst Fence 最大的围栏 2 || dp
原网站大概已经上不了了-- 题目大意: 求出平面上n个点组成的一个包含顶点数最多的凸多边形.n<=250. 考虑我们每次枚举凸包的左下角为谁(参考Graham求凸包时的左下角),然后像Graha ...
- USACO 2006 November Gold Fence Repair /// 贪心(有意思)(优先队列) oj23940
题目大意: 输入N ( 1 ≤ N ≤ 20,000 ) :将一块木板分为n块 每次切割木板的开销为这块木板的长度,即将长度为21的木板分为13和8,则开销为21 接下来n行描述每块木板要求的长度Li ...
- usaco training 3.4.3 fence9 题解
Electric Fence题解 Don Piele In this problem, `lattice points' in the plane are points with integer co ...
- USACO 完结的一些感想
其实日期没有那么近啦……只是我偶尔还点进去造成的,导致我没有每一章刷完的纪念日了 但是全刷完是今天啦 讲真,题很锻炼思维能力,USACO保持着一贯猎奇的题目描述,以及尽量不用高级算法就完成的题解……例 ...
- USACO Training刷题记录 By cellur925
Section 1.1 Your Ride Is Here 貌似没啥可说 Greedy Gift Givers 上来就想stl map映射,有两个坑:如果送给别人的人数为0,那么需要特判一下,防止整数 ...
随机推荐
- Android中那些权限
Permission Permission Permission Group Permission Tree Users Permission ACCESS_CHECKIN_PROPERTIES 允许 ...
- Dev的GridView中如何自动生成行号
这里提供一个方法,使用简单,只需将GridView传入,即可自动生成行号 public static void SetRowNumberIndicator(GridView gridView) { g ...
- Google Dataflow
十分钟了解分布式计算:Google Dataflow 介绍 Google Cloud Dataflow是一种构建.管理和优化复杂数据处理流水线的方法,集成了许多内部技术,如用于数据高效并行化处理的Fl ...
- Mock原理学习
同事搓蛋问了我一个问题,mock的原理是啥,没怎么想出来,于是花了点时间学习了一下. 从Moq这个库入手:https://github.com/moq/moq4 Moq用到了Castle的库用于Dyn ...
- angularjs执行流程
angularjs源码分析之:angularjs执行流程 angularjs用了快一个月了,最难的不是代码本身,而是学会怎么用angular的思路思考问题.其中涉及到很多概念,比如:directi ...
- 使用shell+awk完成Hive查询结果格式化输出
好久不写,一方面是工作原因,有些东西没发直接发,另外的也是习惯给丢了,内因所致.今天是个好日子,走起! btw,实际上这种格式化输出应该不只限于某一种需求,差不多是通用的. 需求: --基本的:当前H ...
- C程序设计语言(第二版)习题:第一章
第一章虽然感觉不像是个习题.但是我还是认真去做,去想,仅此而已! 练习 1-1 Run the "hello, world" program on your system. Exp ...
- NuGet管理
使用NuGet管理项目类库引用 NuGet 是微软开发平台(包括.NET平台)的一个包管理器,这里只介绍和.NET相关的NuGet Visual Studio扩展客户端, 在VS2010 ,VS2 ...
- Asp.net mvc 大文件上传 断点续传
Asp.net mvc 大文件上传 断点续传 进度条 概述 项目中需要一个上传200M-500M的文件大小的功能,需要断点续传.上传性能稳定.突破asp.net上传限制.一开始看到51CTO上的这 ...
- 记一次有趣的互联网事件及console.log~
寂寞的中国互联网又一次瘫痪了. 说是顶级域的根挂了,不知道是黑客还是某个实习生干挂的. 反正到现在还没有人来解释这件事. 先普及一下,为什么顶级域的根挂了全中国都挂了. 那是因为dns解析的特点是递归 ...