跳到正文

题解

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

djh123约 3 分钟
原文
文章信息与版本

文章信息

发布
2018年11月2日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 3 分钟
题目
P4956

版本

  1. v1当前

题目大意:

DavorDavor想要获得N  kunasN~~kunas去旅行,于是他把他的钱放到了旅行基金里。

每周一获得x  kunasx~~kunas,每周二获得x+k  kunasx+k~~kunas,每周三获得x+2k  kunasx+2k~~kunas……每周日获得x+6k  kunasx+6k~~kunas,共5252个周。

DavorDavor恰好获得了N  kunasN~~kunas,现在想要求出合法的最大的xx和最小的kk。

1456≤N≤145600,1≤x≤100,1≤k1456\le N\le 145600, 1\le x\le 100, 1\le k

solvesolve:

先对原式化简:1092k+364x=N1092k+ 364x = N

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

C++
#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;
		}
	}
}
原文