题目传送门

题意:有中文版

分析:首先要知道机器关闭后,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\n", t); continue;
}
cnt++; //忘写,WA一次
while (cnt < n) {
t += w;
cnt++;
}
printf ("%d\n", t);
} return 0;
}

  

最新文章

  1. PHP日志压缩下载
  2. STM3210x建工程库函数版本
  3. 环回接口(loopback interface)的新认识
  4. CSS - Tooltip-arrow 绘制三角形
  5. RxJava简介
  6. python核心编程学习记录之Python对象
  7. windows8.1安装
  8. Vim 配置 winmanager
  9. Android开发之意图解析
  10. squid透明代理+iptables防火墙,多网卡详细配置
  11. Javascript 中创建自定义对象的方法(设计模式)
  12. Java注解处理器--编译时处理的注解
  13. sql 查询 以结果集为对象左连接
  14. vue图片被加了盗链
  15. How to gitignore
  16. 分布式事务XA
  17. python中isdigit
  18. HTML第二篇
  19. oracle 切换用户操作--or--sys用户密码忘记
  20. springboot 表单校验

热门文章

  1. 查看linux接口进出口流量的命令;linux 网络监控;流量监控
  2. Linux OpenSSH后门的加入与防范
  3. 【转载】企业服务总线Enterprise service bus介绍
  4. 项目实战之玩转div+css制作自己定义形状
  5. Git撤销&amp;amp;回滚操作
  6. MIUI应用权限设置
  7. 李洪强iOS开发之性能优化技巧
  8. 使用PowerShell 创建SharePoint 站点
  9. SSH常见错误
  10. POJ1984 Navigation Nightmare —— 种类并查集