Codeforces Round #236 (Div. 2)A(贪心、数学)

来源:互联网 发布:麦茶 日本 知乎 编辑:程序博客网 时间:2024/04/30 19:33

题目链接:http://codeforces.com/contest/402/problem/A


解题思路:

一路贪心,把条件判断好即可。


完整代码:

#include <algorithm>#include <iostream>#include <cstring>#include <complex>#include <cstdio>#include <string>#include <cmath>using namespace std;typedef long long LL;const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const double EPS = 1e-9;const double PI = acos(-1.0); //M_PI;int main(){    #ifdef DoubleQ    freopen("in.txt","r",stdin);    #endif    std::ios::sync_with_stdio(false);    std::cin.tie(0);    int k , a , b , v;    while(cin >> k >> a >> b >> v)    {        int cnt = 0;        while(a > 0)        {            if(b == 0)                a -= v;            else            {                if(b >= k - 1)                {                    a -= k * v;                    b -= k - 1;                }                else                {                    a -= (b + 1) * v;                    b = 0;                }            }            cnt ++;        }        cout << cnt << endl;    }}


0 0
原创粉丝点击