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

 
  1. 3
  2. 5 1 1
  3. 8 10 10
  4. 1000000 1 1000000
Output

 
  1. 5
  2. 8
  3. 499999500000
    读懂题意多判断几次即可(没有想到更好的解法orz)。因为这有个硬性限制是高质量的路段数必须不少于一半,所以先从这里考虑,求出至少的周期个数,再决定低质量的路段是否需要额外的天数。注意:在高质量路段已经修建完成的情况下,低质量的路段也可以在good days修建。
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. long long n,g,b;
  4. int main()
  5. {
  6. int t;
  7. cin>>t;
  8. while(t--)
  9. {
  10. scanf("%d%d%d",&n,&g,&b);
  11. long long half;
  12. if(n%==)half=n/;//至少需要完成的高质量的路段数
  13. else half=n/+;
  14. long long res=n-half;//剩余的路段数
  15. int period=;//周期个数
  16. long long ans=;//答案
  17. if(half%g==)//如果要完成的高质量路段数能被g整除
  18. {
  19. period=half/g;
  20. if(res<=b*period)
  21. {
  22. ans=(period-)*(g+b)+g;
  23. if(res<=(period-)*b)
  24. {
  25. }
  26. else
  27. {
  28. ans=res+period*g;
  29. }
  30. }
  31. else
  32. {
  33. ans=res+period*g;
  34. }
  35. }
  36. else
  37. {
  38. period=half/g+;
  39. ans+=(period-)*g+half%g;
  40. if(res<=(period-)*b)ans+=(period-)*b;
  41. else ans+=res;
  42. }
  43. cout<<ans<<endl;
  44. }
  45. return ;
  46. }
  1.  

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. 素问 - REITs

    摘自<小韭的学习圈> Q 一直以来对REITs感兴趣,看过您微信公众号对REITs的分析,年化8-10%,长期收益稳定,且与其他投资品种关键性低,是很不错的分散配置选择. 您推荐的广发美国 ...

  3. 解决linux 中文乱码

    解决办法是在文件/etc/profile末尾添加一行 echo 'export LC_ALL="en_US.UTF-8"' >> /etc/profile source ...

  4. 关于我 & 关于这个博客

    关于我 OIer,初一在读,蒟蒻,普及组选手,只拿过两次PJ2=,实乃菜也 喜欢数学,OI,OI 上主要研究高级数据结构(如平衡树)和一些不那么暴力的算法(如分块) 打不动 CF . 关于这个博客 是 ...

  5. Linux - Linux中线程为何有PID?

    重现 用htop的Tree view(按F5)之后查看线程 参考 https://segmentfault.com/q/1010000003586656 mousycoder的回答 https://u ...

  6. ALSA driver基本概念

    https://blog.csdn.net/zyuanyun/article/details/59180272#t6 1.Card For each soundcard, a “card” recor ...

  7. MVC简要介绍

    (转自:http://www.cnbeta.com/articles/107924.htm) MVC不是一种设计模式(design pattern),它是一种架构模式(Architectural pa ...

  8. Python隐藏特性:字符串驻留、常量折叠

    下面是Python字符串的一些微妙的特性,绝对会让你大吃一惊. 案例一: >>> a = "some_string" >>> id(a) 140 ...

  9. PHP中PHP $_POST和PHP $_REQUEST及PHP $_GET的用法及区别

     笔者最近开始学习PHP语言大法,记录一下学习过程中遇到的知识点.          今天介绍的是php中有关 php $_post 和 php $_request 及 php $_get 的用法及区 ...

  10. springboot 注解@EnableConfigurationProperties @ConfigurationProperties作用

    @EnableConfigurationProperties 在springboot启动类添加,当springboot程序启动时会立即加载@EnableConfigurationProperties注 ...