码迷,mamicode.com
首页 > 其他好文 > 详细

AGC017B. Moderate Differences

时间:2017-09-23 12:20:59      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:inf   long   code   utc   char   gcd   题意   set   mes   

题意

给出两个数A和B,要求在其中填入N个数字,使得相邻两个数字之差的绝对值在C到D之间

做法

即要构造N个绝对值在CD之间的数其和为B-A,考虑有m个大于0,N-m个小于0,在这样的情况下的和的范围是$[Cm-(N-m)d, Dm-(N-m)C]$,枚举m依次check即可

#include <bits/stdc++.h>
using namespace std;
namespace my_header {
#define pb push_back
#define mp make_pair
#define pir pair<int, int>
#define vec vector<int>
#define pc putchar
#define clr(t) memset(t, 0, sizeof t)
#define pse(t, v) memset(t, v, sizeof t)
#define bl puts("")
#define wn(x) wr(x), bl
#define ws(x) wr(x), pc(‘ ‘)
    const int INF = 0x3f3f3f3f;
    typedef long long LL;
    typedef double DB;
    inline char gchar() {
        char ret = getchar();
        for(; (ret == \n || ret == \r || ret ==  ) && ret != EOF; ret = getchar());
        return ret; }
    template<class T> inline void fr(T &ret, char c =  , int flg = 1) {
        for(c = getchar(); (c < 0 || 9 < c) && c != -; c = getchar());
        if (c == -) { flg = -1; c = getchar(); }
        for(ret = 0; 0 <= c && c <= 9; c = getchar())
            ret = ret * 10 + c - 0;
        ret = ret * flg; }
    inline int fr() { int t; fr(t); return t; }
    template<class T> inline void fr(T&a, T&b) { fr(a), fr(b); }
    template<class T> inline void fr(T&a, T&b, T&c) { fr(a), fr(b), fr(c); }
    template<class T> inline char wr(T a, int b = 10, bool p = 1) {
        return a < 0 ? pc(-), wr(-a, b, 0) : (a == 0 ? (p ? pc(0) : p) : 
            (wr(a/b, b, 0), pc(0 + a % b)));
    }
    template<class T> inline void wt(T a) { wn(a); }
    template<class T> inline void wt(T a, T b) { ws(a), wn(b); }
    template<class T> inline void wt(T a, T b, T c) { ws(a), ws(b), wn(c); }
    template<class T> inline void wt(T a, T b, T c, T d) { ws(a), ws(b), ws(c), wn(d); }
    template<class T> inline T gcd(T a, T b) {
        return b == 0 ? a : gcd(b, a % b); }
    template<class T> inline T fpw(T b, T i, T _m, T r = 1) {
        for(; i; i >>= 1, b = b * b % _m)
            if(i & 1) r = r * b % _m;
        return r; }
};
using namespace my_header;

LL n, a, b, c, d;

int main() {
#ifdef lol
    freopen("b.in", "r", stdin);
    freopen("b.out", "w", stdout);
#endif

    fr(n, a, b);
    fr(c, d);
    bool ok = false;

    for (int i = 0; i < n; ++i) {
        if (c * i - d * (n - i - 1) <= b - a &&
            b - a <= d * i - c * (n - i - 1))
            ok = true;
    }

    if (ok) {
        puts("YES");
    } else puts("NO");

    return 0;
}

 

AGC017B. Moderate Differences

标签:inf   long   code   utc   char   gcd   题意   set   mes   

原文地址:http://www.cnblogs.com/ichn/p/7580213.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!