题解 | #买面包#

买面包

https://ac.nowcoder.com/acm/problem/54838

感觉题意挺意识流。所以解法也应该是意识流解法。

首先根据题意,手上有 aa 元钱,每 bb 元钱买一个面包,所以原价能买 ab\left\lfloor\dfrac{a}{b}\right\rfloor 个面包。

然后是原价购买的面包中,每 cc 个面包能换 dd 个面包,所以能换到的面包数是 abc×d\left\lfloor\dfrac{\left\lfloor\dfrac{a}{b}\right\rfloor}{c}\right\rfloor\times d 个面包。

代码如下:

#include<cstdio>
#define int long long
int init(){
	char c = getchar();
	int x = 0, f = 1;
	for (; c < '0' || c > '9'; c = getchar())
		if (c == '-') f = -1;
	for (; c >= '0' && c <= '9'; c = getchar())
		x = (x << 1) + (x << 3) + (c ^ 48);
	return x * f;
}
void print(int x){
	if (x < 0) x = -x, putchar('-');
	if (x > 9) print(x / 10);
	putchar(x % 10 + '0');
}
signed main(){
	int T = init();
	while (T--) {
		int a = init(), b = init(), c = init(), d = init();
		int buy = a / b;
		int ans = buy + buy / c * d;
		print(ans), putchar('\n');
	}
}
全部评论

相关推荐

点赞 评论 收藏
分享
09-17 17:09
门头沟学院 Java
雨忄:有人给出过解法,拖晚点去,然后到时候再找其他理由商量,既增加他们的筛人成本,不一定会给你收回offer ,也能占位避免工贼
秋招的嫡长offer
点赞 评论 收藏
分享
09-13 18:00
武汉大学 Java
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务