zoukankan      html  css  js  c++  java
  • How Many Points? LightOJ

    题意:

       已知两点 (x1,y1) 和 (x2, y2)求两点间线段上的整点的个数

    解析:

      就是求gcd(abs(x2- x1),abs(y2 - y1))

    证明:

      我们分水平方向和竖直方向两个方向看   这些在线段上的整点的横纵坐标一定可以平分 x2-x1  和  y2-y1 这两条线段

    即需要求这两条线段的最大公约数  使得点最多

    代码转自:https://blog.csdn.net/xiang_6/article/details/78523634   懒得写了

    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<set>
    #include<queue>
    #include<stack>
    #include<map>
    #define PI acos(-1.0)
    #define in freopen("in.txt", "r", stdin)
    #define out freopen("out.txt", "w", stdout)
     
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    const int maxn = 1e6 + 7, maxd = 20 + 7, mod = 1e9 + 7;
    const int INF = 0x7f7f7f7f;
     
    int T;
     
    ll gcd(ll a, ll b) {
        return b == 0 ? a : gcd(b, a%b);
    }
     
    int main() {
        int T;
        scanf("%d", &T);
        for(int tt = 1; tt <= T; ++tt) {
            ll a, b, c, d;
            scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
            ll ans = gcd( abs(a-c), abs(b-d) );
            printf("Case %d: %lld
    ", tt, ans+1);
        }
        return 0;
    }
    View Code
    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    一LWIP学习笔记之数据包管理
    智能家居的发展趋势
    break和continue的区别
    TCP与UDP区别总结
    C语言变量和函数命名规范
    常用电子元件
    php 1018
    php 1016
    mysql 应用查询 三个表(学生表,课程表,学生课程分数表) student, course, score表
    mysql 聚合函数
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/9343078.html
Copyright © 2011-2022 走看看