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
    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    pytorch实现yolov3(1) yolov3基本原理
    python随机选取目录下的若干个文件
    转 Yolov3转化Caffe框架详解
    特征金字塔网络Feature Pyramid Networks
    基于区域的目标检测
    聚类kmeans算法在yolov3中的应用
    车位iou计算
    git常用命令
    opencv 图像旋转
    简单的选项卡制作
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/9343078.html
Copyright © 2011-2022 走看看