Codeforces 864 C Bus
来源:互联网 发布:知乎live分享 编辑:程序博客网 时间:2024/06/08 03:31
题目地址
题意:有一条路长度为a,在路中坐标为f的位置有一个加油站,车子的油箱能装下b升汽油,每公里用一升汽油,问你重复k次路程最少要加几次油,能不能重复k次路程,(一次路程的定义是0->a或者a->0)
思路:我们每次判断油够不够就好了,不够就加油,当油箱满了不能跑那么多路的话就是输出-1,直接模拟就好了,唯一要注意的就是k=1和k=2的情况,特判下就好了(画图就能理解)。
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <cmath>#include <cstdio>#include <algorithm>#include <iomanip>#define N 100010#define M 2000010//双倍#define LL __int64#define inf 0x3f3f3f3f#define lson l,mid,ans<<1#define rson mid+1,r,ans<<1|1#define getMid (l+r)>>1#define movel ans<<1#define mover ans<<1|1using namespace std;const LL mod = 1000000007;const double eps = 0.001;int main() { cin.sync_with_stdio(false); int a, b, f, k; int cnt, ans; while (cin >> a >> b >> f >> k) { cnt = 0; ans = b; if (k > 2) { if (f * 2 > b || (a - f) * 2 > b) { cout << -1 << endl; continue; } } else if (k == 1) { if (f > b || (a - f) > b) { cout << -1 << endl; continue; } } else { if (f > b || (a - f) * 2 > b) { cout << -1 << endl; continue; } } ans -= f; for (int i = 1; i < k; i++) { if (i % 2) { if (ans >= (a - f) * 2) { ans -= (a - f) * 2; } else { cnt++; ans = b - (a - f) * 2;; } } else { if (ans >= f * 2) { ans -= f * 2; } else { cnt++; ans = b - f * 2;; } } } if (k % 2 == 0 && ans < f) { cnt++; } if (k % 2 == 1 && ans < a - f) { cnt++; } cout << cnt << endl; } return 0;}
阅读全文
0 0
- 【Codeforces 864 C. Bus】
- CodeForces 864C Bus
- Codeforces 864 C Bus
- Codeforces 864C Bus(模拟水题)
- Codeforces Round #436 (Div. 2)C. Bus codeforces 864C. Bus
- Codeforces Round #436 (Div. 2) C. Bus
- Codeforces Round #436 (Div. 2) C. Bus
- Codeforces Round #436 (Div. 2) C. Bus
- codeforce 864C Bus(模拟)
- Codeforces Round #436 (Div. 2) C. Bus 来回路程问题
- Codeforces Round #436 (Div. 2) C. Bus(模拟)
- Codeforces Bayan Bus
- 【CODEFORCES】 A. Bayan Bus
- New Bus Rote codeforces
- Codeforces Bus to Udayland
- Queue on Bus Stop CodeForces
- drivers\base\bus.c
- Codeforces Round #436 (Div. 2) A.Fair Game B.Polycarp and Letters C. Bus D.Make a Permutation!
- 泛微OA在传媒行业协同OA系统解决方案
- 关乎vue-awesome-swiper@2.6.7的样式的问题
- linux共享内存详解(转)
- 说明:本文主要介绍五种最常见和最常用的图像格式:BMP,PNG,JPEG,JPEG200,以及GIF
- 创建表
- Codeforces 864 C Bus
- MDL内存映射
- matlab中“存储空间不足,无法处理此命令”
- 亚信(北京)CMC项目组实习第一周总结
- c++中this指针的详尽用法解析
- Tomcat logs文件夹下不同文件的意义
- 是时候该学JavaScript了
- C/C++数组初始化的一些误区
- Android读取M1卡数据