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. 阻塞队列BlockingQueue之ASynchronousQueue

    一.SynchronousQueue简介 Java 6的并发编程包中的SynchronousQueue是一个没有数据缓冲的BlockingQueue,生产者线程对其的插入操作put必须等待消费者的移除 ...

  2. FTP服务:使用 vsftpd 服务传输文件

    1.文件传输协议 今天的互联网是由几千万台个人计算机.工作站.服务器.小型机.大型 机.巨型机等具有不同型号.不同架构的物理设备共同组成的,而且即便是个人计算机,也 可能会装有 Windows.Lin ...

  3. 13.56Mhz下直接阻抗匹配调试步骤

    直接匹配阻抗,天线与射频芯片在同一块板子,调试步骤与50欧姆阻抗匹配调试天线参数差不多,多了一部分射频芯片端的滤波部分的参数计算.下面介绍调试过程. 1.首先看一下射频芯片发射部分原理图:分析原理图时 ...

  4. 如何在IntelliJ Idea中同时启动不同端口的两个实例

    在SpringCloud开发过程中需要在一个项目中启用不同的端口,我使用的工具是IDEA 步骤1 创建SpringBoot工程 步骤2 在配置文件中添加如下配置: spring.application ...

  5. zk zkCli shell命令

    查看zk 注册服务:在zk bin 下执行 sh zkCli.sh 计入客户端shell命令行 查看zk注册服务:ls  /  或者递归查看 ls  -s  /      列出的为注册服务. 查询服务 ...

  6. HADOOP_SECURE_DN_USER has been replaced by HDFS_DATANODE_SECURE_USER

    这个问题可能是我第一个遇到吧,hadoop启动时WARNING: HADOOP_SECURE_DN_USER has been replaced by HDFS_DATANODE_SECURE_USE ...

  7. drf框架,restful接口规范,源码分析

    复习 """ 1.vue如果控制html 在html中设置挂载点.导入vue.js环境.创建Vue对象与挂载点绑定 2.vue是渐进式js框架 3.vue指令 {{ }} ...

  8. 2019冬季PAT甲级第一题

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ][]; ][]; ]; string ...

  9. Petr and a Combination Lock

    Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to r ...

  10. 分析AppClassLoader,ExtClassLoader 和URLClassLoader 的关系

    测试代码: class Hello { public String str = "Hello World"; public void fun() { System.out.prin ...