Codeforces 864C Round#436 C :果然还是模拟最难
来源:互联网 发布:软件模型 编辑:程序博客网 时间:2024/06/04 20:06
题意:有一个小车,在[ 0 , a ]范围内做周期运动。运动轨迹是 0->a->0->a->0->a……,走一趟定义为0->a或者a->0。中间有个加油站,在p的位置。然后小车的油箱容量是b,走一单位的距离就消耗一单位的油。小车路过加油站可以选择不加油,也可以选择把油加满。请问要走k趟,最少需要加几次油。
题解:模拟吧 模拟吧。。。。不说了。。。心塞了。。。atleft记录小车现在是不是在左端点处。tot记录现在走了多少趟了。ans记录加了多少次油。。。然后请大力模拟。
Code:
#include<bits/stdc++.h>using namespace std;typedef long long LL;LL a,bb,b,f,k,c1,c2,rest,cc;int main(){cin>>a>>b>>f>>k;LL c1 = f;LL c2 = a-f;LL ans =0;LL tot =0;LL rest = b;if (c1>b||c2>b){cout<<-1<<endl;return 0;}bool atleft =true;while (tot<k){//cout<<tot<<" "<<atleft<<" "<<rest<<" "<<ans<<endl;LL round = rest/a;if (tot+round>=k){break;}if (round*a==rest){round--;}LL temp = rest-round*a;if (round<0){cout<<-1<<endl;return 0;}if (atleft){if (round&1){if (c2>temp){temp+=a;round--;}}else{if (c1>temp){temp+=a;round--;}}}else{if (round&1){if (c1>temp){temp+=a;round--;}}else{if (c2>temp){temp+=a;round--;}}}if (round<0){cout<<-1<<endl;return 0;}tot+=round;if (tot>=k){break;}if (atleft){if (round&1){rest = b-c1;tot++;ans++;}else{rest = b-c2;tot++;ans++;atleft = false;}}else{if (round&1){rest = b-c2;tot++;ans++;}else{rest = b-c1;tot++;ans++;atleft = true;}}}cout<<ans<<endl;return 0;}
阅读全文
0 0
- Codeforces 864C Round#436 C :果然还是模拟最难
- Codeforces Round #436 (Div. 2) C. Bus(模拟)
- Codeforces Round #346 (Div. 2) C模拟
- Codeforces Round #325 (Div. 2) C 模拟
- Codeforces Round #316 (Div. 2) C 模拟
- Codeforces Round #306 (Div. 2) C 模拟
- Codeforces Round #126 (Div. 2) C 模拟
- Codeforces Round #373 (Div. 2) C 模拟
- Codeforces Round #377 (Div. 2) C 模拟
- codeforces 864C 模拟
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) C 模拟
- Codeforces - Educational Codeforces Round 14C - Exponential notation(模拟)
- Codeforces Round #138 (Div. 2) c 数据结构模拟
- Codeforces Round #306 (Div. 2)C. Divisibility by Eight--模拟
- Codeforces Round #283 (Div. 2) C. Removing Columns 模拟+构造
- Codeforces Round #200 (Div. 2)344C Rational Resistance(模拟)
- C. Replacement( Codeforces Round #316 (Div. 2) 模拟)
- Codeforces Round #316 (Div. 2) C. Replacement (模拟)
- Android Studio里的jni实现方法(一)
- 栈和队列自主学习作业
- NoSQL之Redis高级命令详解--持久化机制
- Linux安装CDH
- [算法基础]几个关于递归算法的练习题
- Codeforces 864C Round#436 C :果然还是模拟最难
- js实现2048小游戏
- find: ‘/run/user/1000/gvfs’: Permission denied
- Problem J. Worried School(日期模拟 STL)
- codevs1063合并果子
- 渗透测试 | 无线渗透 | 2-无线网络架构
- Redis
- 数学之美笔记1
- I2C初始化