CodeForces1345A. Alarm Clock

Polycarp需要睡 a a a分钟, b b b分钟后他的闹钟第一次响,闹钟每一次响如果他还没睡够会让闹钟 c c c分钟后再响,被闹钟吵醒之后他需要 d d d分钟才能睡着,问多久他才能睡够。

注意,即使睡够了,也只有闹钟响的时候Polycarp才会起床。

显然, a ≤ b a\leq b ab时直接输出 b b b即可;

a > b a>b a>b并且 c ≤ d c\leq d cd时,Polycarp永远睡不够;

剩余的情况就是Polycarp在 b b b分钟之后还需要睡 ( a − b ) (a-b) (ab)分钟,每 c c c分钟可以睡 ( c − d ) (c-d) (cd)分钟,计算一下,向上取整

```
#include <bits/stdc++.h>
#define pb push_back 
#define fir first
#define sec second
#define ms(a,b) memset(a,b,sizeof(a)) 
#define INF 0x3f3f3f3f
#define sp system("pause")
using namespace std;
typedef long long ll;
typedef double db;
const int N=1e5+5;
const int mod=10007;
const db pi=acos(-1.0);
int main()
{
    int t;
    ll a,b,c,d;
    cin>>t;
    while(t--)
    {
        cin>>a>>b>>c>>d;
        if(a<=b) 
        {
            cout<<b<<endl;
            continue;
        }
        if(c<=d)
        {
            cout<<-1<<endl;
            continue;
        }
        ll ans=b+(a-b)/(c-d)*c;
        if((a-b)%(c-d)!=0) ans+=c;//手动向上取整,取余不为0就+1
        cout<<ans<<endl;
    }
    #ifndef ONLINE_JUDGE
    sp;
    #endif
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值