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,那么需要特判一下,防止整数 ...
随机推荐
- 删除指定表的所有索引,包括主键索引,唯一索引和普通索引 ,适用于sql server 2005,
原文:删除指定表的所有索引,包括主键索引,唯一索引和普通索引 ,适用于sql server 2005, --删除指定表中所有索引 --用法:declare @tableName varchar(100 ...
- C#编程实践--字符串反转
朴素反转 朴素解法,倒序遍历,字符串拼接,字符串性能低下,在长度已知的前提可以使用char数组代替 public static string NaiveReverse(string text) { s ...
- 经典的SQL语句面试题
Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,Tname) 教师表 问题 ...
- Javascript多线程引擎(七)
Javascript多线程引擎(七)--synchronized关键字 经过两天的努力, 今天synchronzied关键字终于支持了, 如下是测试代码 thread() 是一个开启新线程的API, ...
- [Java]利用拦截器和自定义注解做登录以及权限验证
1.自定义注解 需要验证登录的注解 package com.etaofinance.wap.common; import java.lang.annotation.Documented; import ...
- DesignMode的状态处理
自定义控件开发的调试及DesignMode的状态处理 在开发Winform程序的时候,我们往往需要根据需要做一些自定义的控件模块,这样可以给系统模块重复利用,或者实现更好的效果等功能.但在使用的时候, ...
- 【IOS开发】基础
1.Objective-C 为 ANSI C 添加了下述语法和功能: 定义新的类 类和实例方法 方法调用(称为发消息) 属性声明(以及通过它们自动合成存取方法) 静态和动态类型化 块 (block), ...
- namespace 的作用
在写CPP的时候,常常要写using namespace std;这么一句话,到底有什么用呢? #include <iostream> namespace first { ; } name ...
- Gink掉过的坑(一):将CCTableView导入到lua中
环境: 系统:win7 64位 cocos2dx:cocos2d-2.1rc0-x-2.1.3 Visual Studio: 2012 由于项目是用lua写的,需要将cocos2dx中的方法导入到lu ...
- wcf传输Dataset大数据量 -压缩(一)
wcf传输Dataset大数据量 -压缩(一) 由于WCF不能传输DataTable(不能序列化),所以更多项目中都会使用DataSet作为查询集合的首选返回类型,但是由于DataSet会生成很多的状 ...