• 洛谷P8395 Good Fours and Good Fives


    传送门

    题目描述

    \rm FinnFinn 非常喜欢 44 和 55,他认为所有的数都可以用 44 和 55 进行相加得出。

    例:

    14=5+5+414=5+5+4

    20=4+4+4+4+420=4+4+4+4+4 或 20=5+5+5+520=5+5+5+5

    40=4+4+4+4+4+4+4+4+4+440=4+4+4+4+4+4+4+4+4+4 或 40=4+4+4+4+4+5+5+5+540=4+4+4+4+4+5+5+5+5 或 40=5+5+5+5+5+5+5+540=5+5+5+5+5+5+5+5

    当然,44 和 55 的顺序并不重要,重要的是他们的个数。

    给你一个正整数 nn,问有多少种方法可以用 44 和 55 拼凑成 nn。

    输入格式

    一行,一个整数 nn,表示要被拼凑的数。

    输出格式

    一行,表示方法的数量。如果这个数不能被拼凑,请输出 00。

    输入输出样例

    输入 #1复制
    14
    输出 #1复制
    1
    输入 #2复制
    40
    输出 #2复制
    3
    输入 #3复制
    6
    输出 #3复制
    0

    说明/提示

    对于 20%20% 的数据:1\le n\le 101≤n≤10

    对于另外 15%15% 的数据:1\le n\le10^51≤n≤10
    5
    并且保证 n\equiv0n≡0 \pmod 4(mod4)

    对于另外 15%15% 的数据:1\le n\le10^51≤n≤10
    5
    并且保证 n\equiv0n≡0 \pmod 5(mod5)

    对于 100%100% 的数据:1\le n\le 10^61≤n≤10
    6

    上代码:

    #include
    using namespace std;
    #define int long long
    int read() {
    	int f = 1, x = 0;
    	char c = getchar();
    	while (c < '0' || c > '9') {
    		if (c == '-')f = -1;
    		c = getchar();
    	}
    	while (c >= '0' && c <= '9') {
    		x = x * 10 + c - '0';
    		c = getchar();
    	}
    	return f * x;
    }
    void write(int x) {
    	if (x < 0) {
    		putchar('-');
    		x = -x;
    	}
    	if (x > 9)write(x / 10);
    	putchar(x % 10 + '0');
    }
    int a = 4, b = 5, x, y, n = read(), ans = 0;
    signed main() {
    	x = -n;
    	y = n;
    	while (y >= 0) {
    		x += 5;
    		y -= 4;
    		if (x >= 0 && y >= 0)ans++;
    	}
    	write(ans);
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
  • 相关阅读:
    Android 摇一摇功能实现,重力加速度大于15
    Windows环境中Python应用服务自启动及其监控解决方法
    外贸客户开发信怎么写?如何撰写营销邮件?
    M.2接口电路设计
    Unity框架TEngine转WebGL
    [Android jni] Bitmap与Mat对象的相互转换
    远程线程注入
    uni-app项目总结
    AI网络爬虫003:kimi批量爬取《庆余年》分集剧情
    怎么把开源项目放到自己的github,gitee,gitea上
  • 原文地址:https://blog.csdn.net/lzx_xzl_______/article/details/126523768