zoukankan      html  css  js  c++  java
  • 【hihocoder 1473】小Ho的强迫症

    【题目链接】:http://hihocoder.com/problemset/problem/1473

    【题意】

    【题解】

    假定初始为在在0位置(相对它左边那条线);
    则考虑;
    多少步之后,人又能这到达相对位置为0的点(相对左边那条线);
    应该是L/gcd(L,D)步;
    因为D*L/gcd(L,D)是L,D的最小公倍数;
    且可以证明
    在走的每一步
    在0..L上都是均匀的;
    即,数轴0..L-1上
    把 (k*D)%L记录在这个数轴上(L/GCD(L,D)个点)
    k代表步数;
    第k步就在从左往右数的第k个点上;且相邻两个点之间的距离就为
    gcd(L,D);
    可以想见,在它从0再次变回0的过程中;
    最可能出现踩到边的情况就是倒数第1个点;
    它位于刚才我们说的数轴上的
    第(L/gcd(L,D)-1)个点;
    且它离右端点(L-1)的距离就为gcd(L,D)->这是距离最短的了;
    则只要这个gcd(L,D)>=F,则可以;
    否则不行.

    【Number Of WA

    0

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define ms(x,y) memset(x,y,sizeof x)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    const int N = 110;
    
    LL L,F,D;
    int T;
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not use
        cin >> T;
        while (T--)
        {
            cin >> L >> F >> D;
            if (__gcd(L,D)>=F)
                cout << "YES"<<endl;
            else
                cout << "NO"<<endl;
        }
        return 0;
    }
    
  • 相关阅读:
    59. Spiral Matrix II
    58. Length of Last Word
    57. Insert Interval
    56. Merge Intervals
    55. Jump Game
    54. Spiral Matrix
    53. Maximum Subarray
    52. N-Queens II
    51. N-Queens
    java封装学习
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626373.html
Copyright © 2011-2022 走看看