题解:P5709 【深基2.习6】Apples Prologue / 苹果和虫子

· · 题解

思路:

有 m 个苹果,每 t 分钟能吃一个苹果,吃了 s 分钟,问还有几个完整的苹果。我们可以知道,在 s 分钟内,可以吃 s \div t 个苹果。那么剩下的就是 m - s \div t 个苹果。注意 t 是否为 0。s \div t 要向下取整。

代码:

#include<bits/stdc++.h>
using namespace std;
int m,t,s;
int main()
{
    cin>>m>>t>>s;
    if(t==0)
    {
        cout<<0<<endl;
        return 0;
    }
    if(s%t==0)
        {
            if(m-s/t>=0)
            cout<<m-s/t;
            else cout<<0;
        }
    else
        {
            if(m-s/t-1>=0)
            cout<<m-s/t-1;
            else cout<<0;
        }
    return 0;
}