题意:有中文版的
分析:首先要知道机器关闭后,w是清零的。所以一次(x + y)的循环弹出的小球个数是固定的,为x / w + 1,那么在边界时讨论一下就行了
收获:这种题目不难,理解清楚题意,yy出可行的解法总能做出来
代码:
/************************************************ * Author :Running_Time * Created Time :2015-8-22 18:55:05 * File Name :A.cpp ************************************************/ #include <cstdio> #include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; int main(void) { int x, y, w, n; while (scanf ("%d%d%d%d", &x, &y, &w, &n) == 4) { int cnt = 0; int t = 0; int a = x / w + 1; while (cnt + a <= n) { cnt += a; if (cnt == n) { t += (a - 1) * w; break; } else if (cnt == n - 1) { t += x + y; break; } else t += (x + y); } if (cnt == n || cnt == n - 1) { printf ("%d ", t); continue; } cnt++; //忘写,WA一次 while (cnt < n) { t += w; cnt++; } printf ("%d ", t); } return 0; }