zoukankan      html  css  js  c++  java
  • Minimum Integer CodeForces

    You are given qq queries in the following form:

    Given three integers lili, riri and didi, find minimum positive integer xixi such that it is divisible by didi and it does not belong to the segment [li,ri][li,ri].

    Can you answer all the queries?

    Recall that a number xx belongs to segment [l,r][l,r] if lxrl≤x≤r.

    Input

    The first line contains one integer qq (1q5001≤q≤500) — the number of queries.

    Then qq lines follow, each containing a query given in the format lili riri didi (1liri1091≤li≤ri≤109, 1di1091≤di≤109). lili, riri and didi are integers.

    Output

    For each query print one integer: the answer to this query.

    Example

    Input
    5
    2 4 2
    5 10 4
    3 10 1
    1 2 3
    4 6 5
    
    Output
    6
    4
    1
    3
    10

    题目链接:CodeForces - 1101A 
    水题一个,但是数据量略大不足以让我们暴力随便过。
    那么便思考一下找公式就行了,
    观察可知,当d小于L的时候,答案就是d
    否则,答案是
    (r/d+1)*d;

    我的AC代码:
     #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <queue>
    #include <stack>
    #include <map>
    #include <set>
    #include <vector>
    #define rep(i,x,n) for(int i=x;i<n;i++)
    #define repd(i,x,n) for(int i=x;i<=n;i++)
    #define pii pair<int,int>
    #define pll pair<long long ,long long>
    #define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
    #define MS0(X) memset((X), 0, sizeof((X)))
    #define MSC0(X) memset((X), '', sizeof((X)))
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define gg(x) getInt(&x)
    using namespace std;
    typedef long long ll;
    inline void getInt(int* p);
    const int maxn=1000010;
    const int inf=0x3f3f3f3f;
    /*** TEMPLATE CODE * * STARTS HERE ***/
    int q;
    int l,r;
    int d;
    int main()
    {
        gbtb;
        cin>>q;
        while(q--)
        {
            cin>>l>>r>>d;
            int flag=0;
            if(d<l)
            {
                cout<<d<<endl;
                continue;
            }else
            {
                int ans=(r/d+1)*d;
                cout<<ans<<endl;
            }
        }
        return 0;
    }
    
    inline void getInt(int* p) {
        char ch;
        do {
            ch = getchar();
        } while (ch == ' ' || ch == '
    ');
        if (ch == '-') {
            *p = -(getchar() - '0');
            while ((ch = getchar()) >= '0' && ch <= '9') {
                *p = *p * 10 - ch + '0';
            }
        }
        else {
            *p = ch - '0';
            while ((ch = getchar()) >= '0' && ch <= '9') {
                *p = *p * 10 + ch - '0';
            }
        }
    }
     
    本博客为本人原创,如需转载,请必须声明博客的源地址。 本人博客地址为:www.cnblogs.com/qieqiemin/ 希望所写的文章对您有帮助。
  • 相关阅读:
    pandas Dataframe filter
    process xlsx with pandas
    data manipulate in excel with easyExcel class
    modify registry in user environment
    add number line in vim
    java import webservice
    ctypes MessageBoxA
    music 163 lyrics
    【python实例】自动贩卖机
    【python基础】sys模块(库)方法汇总
  • 原文地址:https://www.cnblogs.com/qieqiemin/p/10259423.html
Copyright © 2011-2022 走看看