题解 P4956 【[COCI2017-2018#6] Davor】

· · 题解

题目大意:

每周一获得$x~~kunas$,每周二获得$x+k~~kunas$,每周三获得$x+2k~~kunas$……每周日获得$x+6k~~kunas$,共$52$个周。 $Davor$恰好获得了$N~~kunas$,现在想要求出合法的最大的$x$和最小的$k$。 $1456\le N\le 145600, 1\le x\le 100, 1\le k 先对原式化简:$1092k+ 364x = N

考虑到x的数据很小,所以可以枚举x。

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <bitset>

using namespace std;

struct FastIO
{
    inline FastIO& operator >> (int& x) {
        x = 0; char f = 0, ch = getchar();
        while(ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
        while(ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
        return x = (f ? -x : x), *this;
    }
    inline FastIO& operator >> (long long& x) {
        x = 0; char f = 0, ch = getchar();
        while(ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
        while(ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
        return x = (f ? -x : x), *this;
    }
    inline FastIO& operator >> (double& x)
    {
        x = 0; char f = 0, ch = getchar();
        double d = 0.1;
        while(ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
        while(ch <= '9' && ch >= '0') x=x * 10 + ch - 48, ch = getchar();
        if(ch == '.')
        {
            ch = getchar();
            while(ch <= '9' && ch >= '0') x += d * (ch ^ 48), d *= 0.1, ch = getchar();
        }
        return x = (f ? -x : x), *this;
    }
}rin;

int main() {
    int n;
    rin >> n;
    for(int i = 100 ; i >= 1 ; -- i) {//枚举x
        int x = 364 * i;
        int now = n - x;
        if(now < 0) continue;
        if((now % 1092 == 0) && (now != 0)) {//判断是否合法
            printf("%d\n%d\n", i, now / 1092);//输出解
            return 0;
        }
    }
}