zoukankan      html  css  js  c++  java
  • 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
     1 /*
     2 ID: ivorysi
     3 PROG: fence9
     4 LANG: C++
     5 */
     6 #include <iostream>
     7 #include <cstdio>
     8 #include <cstring>
     9 #include <algorithm>
    10 #include <queue>
    11 #include <set>
    12 #include <vector>
    13 #include <string.h>
    14 #define siji(i,x,y) for(int i=(x);i<=(y);++i)
    15 #define gongzi(j,x,y) for(int j=(x);j>=(y);--j)
    16 #define xiaosiji(i,x,y) for(int i=(x);i<(y);++i)
    17 #define sigongzi(j,x,y) for(int j=(x);j>(y);--j)
    18 #define inf 0x3f3f3f3f
    19 #define MAXN 400005
    20 #define ivorysi
    21 #define mo 97797977
    22 #define ha 974711
    23 #define ba 47
    24 #define fi first
    25 #define se second
    26 #define pii pair<int,int>
    27 using namespace std;
    28 typedef long long ll;
    29 int n,m,p;
    30 int s,k;
    31 int gcd(int a,int b) {return b==0 ? a : gcd(b,a%b);}
    32 void solve() {
    33     scanf("%d%d%d",&n,&m,&p);
    34     s=p*m;
    35     k=k+gcd(m,n)-1;
    36     k=k+gcd(abs(n-p),m)-1;
    37     k=k+2+p;
    38     int ans=(s-k+2)/2;
    39     printf("%d
    ",ans);
    40 }
    41 int main(int argc, char const *argv[])
    42 {
    43 #ifdef ivorysi
    44     freopen("fence9.in","r",stdin);
    45     freopen("fence9.out","w",stdout);
    46 #else
    47     freopen("f1.in","r",stdin);
    48 #endif
    49     solve();
    50 }
     
  • 相关阅读:
    Selenium(一):元素定位
    白盒测试系列(五)条件组合覆盖
    LDAP(轻型目录访问协议)
    Spring Intorduce、History and Design Philosophy
    CORS
    mysql创建用户并授权某个数据库
    Introduce Servlet 、Filter
    web.xml的简单解释以及Hello1中web.xml的简单分析
    ANNOTATION and analyse hello1.java
    Analysis of container and Injection in Java, their history and future.
  • 原文地址:https://www.cnblogs.com/ivorysi/p/6242909.html
Copyright © 2011-2022 走看看