Codeforces 864 C Bus
2017-10-23 11:40
316 查看
题目地址
题意:有一条路长度为a,在路中坐标为f的位置有一个加油站,车子的油箱能装下b升汽油,每公里用一升汽油,问你重复k次路程最少要加几次油,能不能重复k次路程,(一次路程的定义是0->a或者a->0)
思路:我们每次判断油够不够就好了,不够就加油,当油箱满了不能跑那么多路的话就是输出-1,直接模拟就好了,唯一要注意的就是k=1和k=2的情况,特判下就好了(画图就能理解)。
题意:有一条路长度为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|1 using 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; c548 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; }
相关文章推荐
- codeforces 864 F
- codeforces——contest 864 problemE
- codeforces contest 864 problemD
- CodeForces 864
- 【Codeforces 864 C. Bus】
- 【CodeForces - 864】 A B C【模拟】 D【贪心+优先队列】
- Codeforces 864 D Make a Permutation!
- Codeforces 864D D. Make a Permutation!【思维+线段树+二分+这是一个煞笔做法】
- CodeForces - 777C Alyona and Spreadsheet (vector存储二维数组)
- codeforces 839A 428 Div2 B Game of the Rows
- [数论][构造][离散对数] Codeforces 913 G. Power Substring
- Codeforces 653A: Tricky Sum(数学)
- CodeForces 235C Cyclical Quest(后缀自动机)
- Codeforces 380C. Sereja and Brackets【线段树】
- codeforces 472BDesign Tutorial: Learn from Life(简单贪心)
- Codeforces 761E Dasha and Puzzle【构造,树dfs】
- codeforces-305A Strange Addition(思维+模拟)
- codeforces 586c The Big Race 【数据超出long long 范围】
- CodeForces 659 B. Qualifying Contest(结构体排序的问题)
- [codeforces 734F]Anton and School