洛谷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<bits/stdc++.h>
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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
A: 以下是代码示例: ``` #include<iostream> #include<iomanip> using namespace std; void PrintScorecard(int die1, int die2, int die3, int die4, int die5, int round1, int round2, int round3, int round4, int round5, int round6, int round7, int round8, int round9, int round10, int round11, int round12, int round13) { int totalScore = round1 + round2 + round3 + round4 + round5 + round6 + round7 + round8 + round9 + round10 + round11 + round12 + round13; cout << "Scorecard" << endl << endl; cout << left << setw(25) << "Ones:" << setw(5) << die1 << " " << right << setw(5) << round1 << " " << left << setw(5) << (die1 == 1 ? die1 : "-") << " " << right << setw(5) << (round1 != 0 ? round1 : "-") << endl; cout << left << setw(25) << "Twos:" << setw(5) << die2 << " " << right << setw(5) << round2 << " " << left << setw(5) << (die2 == 2 ? die2 : "-") << " " << right << setw(5) << (round2 != 0 ? round2 : "-") << endl; cout << left << setw(25) << "Threes:" << setw(5) << die3 << " " << right << setw(5) << round3 << " " << left << setw(5) << (die3 == 3 ? die3 : "-") << " " << right << setw(5) << (round3 != 0 ? round3 : "-") << endl; cout << left << setw(25) << "Fours:" << setw(5) << die4 << " " << right << setw(5) << round4 << " " << left << setw(5) << (die4 == 4 ? die4 : "-") << " " << right << setw(5) << (round4 != 0 ? round4 : "-") << endl; cout << left << setw(25) << "Fives:" << setw(5) << die5 << " " << right << setw(5) << round5 << " " << left << setw(5) << (die5 == 5 ? die5 : "-") << " " << right << setw(5) << (round5 != 0 ? round5 : "-") << endl; cout << endl; cout << left << setw(25) << "Three of a Kind:" << right << setw(5) << round6 << " " << right << setw(5) << (round6 != 0 ? round6 : "-") << endl; cout << left << setw(25) << "Four of a Kind:" << right << setw(5) << round7 << " " << right << setw(5) << (round7 != 0 ? round7 : "-") << endl; cout << left << setw(25) << "Full House:" << right << setw(5) << round8 << " " << right << setw(5) << (round8 != 0 ? round8 : "-") << endl; cout << left << setw(25) << "Small Straight:" << right << setw(5) << round9 << " " << right << setw(5) << (round9 != 0 ? round9 : "-") << endl; cout << left << setw(25) << "Large Straight:" << right << setw(5) << round10 << " " << right << setw(5) << (round10 != 0 ? round10 : "-") << endl; cout << left << setw(25) << "Yahtzee:" << right << setw(5) << round11 << " " << right << setw(5) << (round11 != 0 ? round11 : "-") << endl; cout << left << setw(25) << "Chance:" << right << setw(5) << round12 << " " << right << setw(5) << (round12 != 0 ? round12 : "-") << endl; cout << endl; cout << left << setw(25) << "Total Score:" << right << setw(5) << totalScore << endl; } int main() { int die1, die2, die3, die4, die5; int round1 = 0, round2 = 0, round3 = 0, round4 = 0, round5 = 0, round6 = 0, round7 = 0, round8 = 0, round9 = 0, round10 = 0, round11 = 0, round12 = 0, round13 = 0; // Code to roll dice and update rounds goes here PrintScorecard(die1, die2, die3, die4, die5, round1, round2, round3, round4, round5, round6, round7, round8, round9, round10, round11, round12, round13); return 0; } ``` 输出示例: ``` Scorecard Ones: 3 3 - - Twos: 2 4 2 4 Threes: 5 - - 5 Fours: 1 - - - Fives: 6 10 - 10 Three of a Kind: - - 10 - Four of a Kind: - - - - Full House: - - - - Small Straight: - - 15 - Large Straight: - - - - Yahtzee: - - 0 - Chance: - 14 - - Total Score: 29 ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值