Educational Codeforces Round 82 B. National Project
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?
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.
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.
3
5 1 1
8 10 10
1000000 1 1000000
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的更多相关文章
- 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 ...
- [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 ...
- 【题解】Educational Codeforces Round 82
比较菜只有 A ~ E A.Erasing Zeroes 题目描述: 原题面 题目分析: 使得所有的 \(1\) 连续也就是所有的 \(1\) 中间的 \(0\) 全部去掉,也就是可以理解为第一个 \ ...
- Educational Codeforces Round 82 (Rated for Div. 2)
题外话 开始没看懂D题意跳了,发现F题难写又跳回来了.. 语文好差,码力好差 A 判第一个\(1\)跟最后一个\(1\)中\(0\)的个数即可 B 乘乘除除就完事了 C 用并查集判一下联通,每个联通块 ...
- 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; ][]; ...
- Educational Codeforces Round 82 (Rated for Div. 2)D(模拟)
从低位到高位枚举,当前位没有就去高位找到有的将其一步步拆分,当前位多余的合并到更高一位 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h&g ...
- Educational Codeforces Round 82 C. Perfect Keyboard
Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him ...
- 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 ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
随机推荐
- 服务端捡起或丢弃指定物品ID触发详解
传奇服务端捡起或丢弃指定物品ID触发详解: @PickUpItemsX X是物品数据库中对应的IDX@DropItemsX X是物品数据库中对应的IDX@H.PickUpItemsX X是物品数据库中 ...
- 百炼OJ - 1003 - Hangover
题目链接 思路 求一个数列的前n项和(1/2, 1/3, ...., 1/n)大于所给数所需的项数. #include<stdio.h> int main() { float a; whi ...
- docker-api的使用(java)
通过docker-api来执行docker相关的操作. 配置 可以在docker启动文件docker.service中加入如下 vi /lib/systemd/system/docker.serv ...
- 工厂方法模式(JAVA反射)
简单工厂模式的不足 在简单工厂模式中,只提供了一个工厂类,该工厂类处于对产品类进行实例化的中心位置,它知道每一个产品对象的创建细节,并决定何时实例化哪一个产品类.简单工厂模式最大的缺点是当有新 ...
- 【Webex】加入会议是无法正常加入!提示“下载会议组件时无法获取正确的参数。 请联系技术支持以获取帮助。
来自:Cisco Webex帮助中心 https://help.webex.com/zh-cn/WBX9000023909/Error-Failed-to-get-correct-parameters ...
- JQuery中的DOM操作(转载)
原文链接:http://www.cnblogs.com/ILYljhl/archive/2013/07/10/3182414.html jQuery封装了大量DOM操作的API,极大提高了操作DOM节 ...
- 507,介绍一下标准的css盒子模型?低版本ie的盒子模型有什么不同的?
有两种,IE盒子模型,另外是W3C盒子模型: 盒模型都包括:内容(content),填充(padding),边界(margin),边框(border): 区别:IE的content部分吧border和 ...
- MBA 报考
1. 作者:MBA薛老师链接:https://www.zhihu.com/question/277811289/answer/397083199来源:知乎著作权归作者所有.商业转载请联系作者获得授 ...
- Scala实现网站流量实时分析
之前已经完成zookeeper集群.Hadoop集群.HBase集群.Flume.Kafka集群.Spark集群的搭建:使用Docker搭建Spark集群(用于实现网站流量实时分析模块),且离线分析模 ...
- 【原】移动端vue页面点透事件 - 分析与解决
近期项目遇到了vue页面事件被带到下一个页面的问题,也就是我们常说的点透事件,主要表现在android机器上,花了不少时间折腾,简单做下总结~ vue页面之间的切换通过Vue Router的route ...