Educational Codeforces Round 1303B #82 (Rated for Div. 2) B. Perfect Keyboard 解题思路 - 思维题

本文介绍了Educational Codeforces Round 1303B的第82场竞赛中的问题B——Perfect Keyboard。题目涉及在周期性气候条件下,修复一条长度为�的公路,好天气(g天)和坏天气(b天)交替出现。目标是确保至少一半的公路是高质量的。求解修复整个公路所需的最短天数。示例展示了不同输入输出情况,强调即使在好天气下每天工作,也可能达到最少工作天数的要求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Educational Codeforces Round 1303B #82 (Rated for Div. 2) B. Perfect Keyboard

Your company was appointed to lay new asphalt on the highway of length 𝑛. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing.

Skipping the repair is necessary because of the climate. The climate in your region is periodical: there are 𝑔 days when the climate is good and if you lay new asphalt these days it becomes high-quality pavement; after that, the weather during the next 𝑏 days is bad, and if you lay new asphalt these days it becomes low-quality pavement; again 𝑔 good days, 𝑏 bad days and so on.

You can be sure that you start repairing at the start of a good season, in other words, days 1,2,…,𝑔 are good.

You don’t really care about the quality of the highway, you just want to make sure that at least half of the highway will have high-quality pavement. For example, if the 𝑛=5 then at least 3 units of the highway should have high quality; if 𝑛=4 then at least 2 units should have high quality.

What is the minimum number of days is needed to finish the repair of the whole highway?

Input

The first line contains a single integer 𝑇 (1≤𝑇≤104) — the number of test cases.

Next 𝑇 lines contain test cases — one per line. Each line contains three integers 𝑛, 𝑔 and 𝑏 (1≤𝑛,𝑔,𝑏≤109) — the length of the highway and the number of good and bad days respectively.

Output

Print 𝑇 integers — one per test case. For each test case, print the minimum number of days required to repair the whole highway if at least half of it should have high quality.

Example
input

3
5 1 1
8 10 10
1000000 1 1000000

output

5
8
499999500000

Note

In the first test case, you can just lay new asphalt each day, since days 1,3,5 are good.

In the second test case, you can also lay new asphalt each day, since days 1-8 are good.

有n天需要工作。有这么一个规则,连续g天是好天气,再连续b天是坏天气。如果在好天气工作可以做好,要求至少有n/2向上取整天数做好的个数。你可以选择休息,但是有n天的工作等着你,也就是说随便你休息多少天,但是至少要n天工作。求最小的天数完成工作。

注意:n天的工作量是必须完成的,不管做的好还是做不好。见第二个样例。

/// @author zhaolu

#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <sstream>
#include <algorithm>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repe(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define clc(a,b) memset(a,b,sizeof(a))
#define INF (0x3f3f3f3f)
#define MOD (1000000007)
#define MAX (100000)
#define LEN (MAX+10)
typedef long long ll;
using namespace std;

int t;
long long n,g,b,tmp;
int sum;
long long ans;
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld%lld%lld",&n,&g,&b);
        tmp=n;
        n=(n+1)>>1;
        if(n%g==0) ans=(g+b)*(n/g)-b;
        else ans=(g+b)*(n/g)+n%g;
        printf("%lld\n",max(ans,tmp));
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值