Your company was appointed to lay new asphalt on the highway of length nn. 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 gg days when the weather is good and if you lay new asphalt these days it becomes high-quality pavement; after that, the weather during the next bb days is bad, and if you lay new asphalt these days it becomes low-quality pavement; again gg good days, bb 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,…,g1,2,…,g 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 n=5n=5 then at least 33 units of the highway should have high quality; if n=4n=4 then at least 22 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 TT (1≤T≤1041≤T≤104) — the number of test cases.

Next TT lines contain test cases — one per line. Each line contains three integers nn, gg and bb (1≤n,g,b≤1091≤n,g,b≤109) — the length of the highway and the number of good and bad days respectively.

Output

Print TT 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
读懂题意多判断几次即可(没有想到更好的解法orz)。因为这有个硬性限制是高质量的路段数必须不少于一半,所以先从这里考虑,求出至少的周期个数,再决定低质量的路段是否需要额外的天数。注意:在高质量路段已经修建完成的情况下,低质量的路段也可以在good days修建。
#include <bits/stdc++.h>
using namespace std;
long long n,g,b;
int main()
{
int t;
cin>>t;
while(t--)
{
scanf("%d%d%d",&n,&g,&b);
long long half;
if(n%==)half=n/;//至少需要完成的高质量的路段数
else half=n/+;
long long res=n-half;//剩余的路段数
int period=;//周期个数
long long ans=;//答案
if(half%g==)//如果要完成的高质量路段数能被g整除
{
period=half/g;
if(res<=b*period)
{
ans=(period-)*(g+b)+g;
if(res<=(period-)*b)
{
}
else
{
ans=res+period*g;
}
}
else
{
ans=res+period*g;
}
}
else
{
period=half/g+;
ans+=(period-)*g+half%g;
if(res<=(period-)*b)ans+=(period-)*b;
else ans+=res;
}
cout<<ans<<endl;
}
return ;
}

Educational Codeforces Round 82 B. National Project的更多相关文章

  1. Educational Codeforces Round 82 (Rated for Div. 2) A-E代码(暂无记录题解)

    A. Erasing Zeroes (模拟) #include<bits/stdc++.h> using namespace std; typedef long long ll; ; in ...

  2. [CF百场计划]#3 Educational Codeforces Round 82 (Rated for Div. 2)

    A. Erasing Zeroes Description You are given a string \(s\). Each character is either 0 or 1. You wan ...

  3. 【题解】Educational Codeforces Round 82

    比较菜只有 A ~ E A.Erasing Zeroes 题目描述: 原题面 题目分析: 使得所有的 \(1\) 连续也就是所有的 \(1\) 中间的 \(0\) 全部去掉,也就是可以理解为第一个 \ ...

  4. Educational Codeforces Round 82 (Rated for Div. 2)

    题外话 开始没看懂D题意跳了,发现F题难写又跳回来了.. 语文好差,码力好差 A 判第一个\(1\)跟最后一个\(1\)中\(0\)的个数即可 B 乘乘除除就完事了 C 用并查集判一下联通,每个联通块 ...

  5. Educational Codeforces Round 82 (Rated for Div. 2)E(DP,序列自动机)

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ],t[]; int n,m; ][]; ...

  6. Educational Codeforces Round 82 (Rated for Div. 2)D(模拟)

    从低位到高位枚举,当前位没有就去高位找到有的将其一步步拆分,当前位多余的合并到更高一位 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h&g ...

  7. Educational Codeforces Round 82 C. Perfect Keyboard

    Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him ...

  8. Educational Codeforces Round 82 A. Erasing Zeroes

    You are given a string ss. Each character is either 0 or 1. You want all 1's in the string to form a ...

  9. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

随机推荐

  1. Centos7 安装 Cockpit

    1sudo yum -y install epel-release sudo yum -y update sudo shutdown -r now 2yum -y install cockpit sy ...

  2. PHP SDK+Oss 上传文件流

    // Endpoint以杭州为例,其它Region请按实际情况填写. $endpoint = "http://oss-cn-hangzhou.aliyuncs.com"; // 云 ...

  3. 【音乐欣赏】《Abnormalize》 - 凛として時雨

    曲名:Abnormalize 作者:凛として時雨 [00:00.96]誰にも見せられないもの [00:06.44]頭の中溢れて [00:11.96]間違いさえも無い世界へ [00:17.16]迷い込ん ...

  4. 新手学习PHP的避雷针,这些坑在PHP开发中就别跳了

    不要!用记事本编辑php文件 早些年能用记事本编程是一些人自我吹嘘的资本,能用记事本编程就是牛逼的代名词.但是这里要告诫大家的是,千万不要使用Windows自带的记事本编辑任何文本文件.用Window ...

  5. 【做题笔记】洛谷P1955[NOI2015]程序自动分析

    第一道蓝题祭- 注意到本题中判断的是下标,即,并不是真的判断 \(i\) 是否等于 \(j\) 显然考虑并查集,把所有标记为"相等"的数放在一个集合里,然后最后扫一遍每个数,如果有 ...

  6. Elasticsearch系列---shard内部原理

    概要 本篇我们来看看shard内部的一些操作原理,了解一下人家是怎么玩的. 倒排索引 倒排索引的结构,是非常适合用来做搜索的,Elasticsearch会为索引的每个index为analyzed的字段 ...

  7. SpringCloud Netflix Ribbon

    Eureka客户端的负载均衡:从Eureka server拿到节点列表,客户端自己使用负载均衡的算法确定要使用的节点: Eureka服务端的负载均衡:服务端使用负载均衡的算法,从节点列表中确定要使用的 ...

  8. Apollo安装教程

    最近一直在研究Apollo的安装问题,浪费了几天时间,所有特意来记录一下安装心得. UBUNTU 14.04安装 这个我是把自己的笔记本全部转换为ubuntu系统,操作相对简单,大家可以自行查找,另外 ...

  9. MongoDB C#驱动使用方法

    string connStr = ConfigurationManager.ConnectionStrings["MongoDBConnStr"].ConnectionString ...

  10. django项目日志

    接口中,写一条日志: 日志工具文件如下: