Educational Codeforces Round 82 (Rated for Div. 2) B. National Project (数学)

在这里插入图片描述
题目传送

题目大意:
一共有n段路要修,连续g天修好的,连续b天修坏的,如此循环,坏的路不能超过总的一半。求最短天数。

分析:
当g>=n || g>=b 时,结果就是n。
当g<b时,只考虑修好的,q=(n+1)/2;如果q%m==0 则ans=(q/m)*m+(q/m-1)*b,否则ans=(q/m) * (m+b).

#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long

int main(void)
{
	int t;
	cin >> t;
	while (t--) {
		ll n, m, b, ans;
		cin >> n >> m >> b;
		ll q = (n + 1) / 2;
		if (q % m == 0) {
			ans = q / m;
			ans = ans * m + (ans - 1) * b;
		}
		else {
			ans = q / m;
			ans = ans * (m + b) + q % m;
		}
		cout << max(n, ans) << endl;
	}
	return 0;
}
发布了30 篇原创文章 · 获赞 50 · 访问量 5301

猜你喜欢

转载自blog.csdn.net/qq_43054573/article/details/104292801
今日推荐