zoukankan      html  css  js  c++  java
  • 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?

    Input

    The first line contains a single integer TT (1T1041≤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 (1n,g,b1091≤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%2==0)half=n/2;//至少需要完成的高质量的路段数 
            else half=n/2+1;
            long long res=n-half;//剩余的路段数 
            int period=0;//周期个数 
            long long ans=0;//答案 
            if(half%g==0)//如果要完成的高质量路段数能被g整除 
            {
                period=half/g;
                if(res<=b*period)
                {
                    ans=(period-1)*(g+b)+g;
                    if(res<=(period-1)*b)
                    {
                    }
                    else
                    {
                        ans=res+period*g;
                    }
                }
                else
                {
                    ans=res+period*g;
                }
            }
            else
            {
                period=half/g+1;
                ans+=(period-1)*g+half%g;
                if(res<=(period-1)*b)ans+=(period-1)*b;
                else ans+=res;
            }
            cout<<ans<<endl;
        }
        return 0;
    }



  • 相关阅读:
    超值干货:微服务架构下如何解耦,对于已经紧耦合下如何重构?
    程序员收藏不看系列:近三万字总结Spring注解开发!
    干货收藏:6 款能挣钱的 Spring Boot 开源后台管理系统
    美团二面:你向 Mysql 数据库插入 100w 条数据用了多久?
    5分钟快速掌握阿里内部MySQL性能优化的核心技术!
    优秀!一鼓作气学会“一致性哈希”,就靠这 18 张图了
    分库分表神器 Sharding-JDBC,几千万的数据你不搞一下?
    熬夜肝出5大点,18张图带你彻底弄懂MySQL事务日志
    jdk8新特性Stream
    java多线程
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12303117.html
Copyright © 2011-2022 走看看