Codeforce Round #438 C.Bus(贪心)
来源:互联网 发布:数控车g76编程实例 编辑:程序博客网 时间:2024/06/05 03:49
题目链接:Bus
#include <iostream>#include <cstdio>#include <fstream>#include <algorithm>#include <cmath>#include <deque>#include <vector>#include <queue>#include <string>#include <cstring>#include <map>#include <stack>#include <set>#define Max(a,b) a>b?a:b#define Min(a,b) a>b?b:a#define mem(a,b) memset(a,b,sizeof(a))using namespace std;typedef long long ll;int dir[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};const double eps = 1e-6;const double Pi = acos(-1.0);const int INF=0x3f3f3f3f;ll fuel[10010];ll a,b,f,k;ll dis,ans;ll ind,now;bool flag;int main(){ while(~scanf("%lld%lld%lld%lld",&a,&b,&f,&k)){ mem(fuel,0); flag = true; fuel[0] = 0; for(int i = 1; i <= k; i++){ if(i&1) fuel[i] = a*i - (a-f); else fuel[i] = a*i - f; } fuel[k+1] = a*k; dis = 0,ans = 0,now = 0; while(dis < a*k){ ind = lower_bound(fuel,fuel+k+2,dis+b) - fuel; if(fuel[ind] != dis+b){ ind = ind - 1; } if(ind == now){ flag = false; break; } now = ind; dis = fuel[now]; ans++; } if(flag) printf("%lld\n",ans-1); else printf("-1\n"); } return 0;}
阅读全文
0 0
- Codeforce Round #438 C.Bus(贪心)
- codeforce Round #379 (Div. 2)C(贪心)
- CodeForce 492C(贪心)
- codeforce 864C Bus(模拟)
- codeforce round#410 C(套路)
- codeforce round 399# C
- Codeforce round# 380 E(贪心,构造)
- CodeForce 463C Gargari and Bishops(贪心+暴力)
- CodeForce 508C Anya and Ghosts (贪心+模拟)
- CodeForce 538C Tourist's Notes(贪心 + 数学)
- codeforce 551C GukiZ hates Boxes(二分+贪心)
- codeforce round#261(Div2)
- codeforce round #295(div2) C题
- 【codeforce】Round #402 Div.2 C
- Codeforce Round #400 C 签到题
- Codeforce Round #384 (Div 2) C
- Codeforce Round #439 A B C 题解
- Educational Codeforces Round 12(C)贪心
- 监控ThreadPoolExecutor具体Task在Queue中等待时间
- Graduation Project Day 1
- 字符串反转(按单词正序输出),保留并打印所有空格。
- Openjudge 06:月度开销
- 一个斐波那契数列的前10项为:1, 2, 3, 5, 8, 13, 21, 34, 55, 89,对于一个最大项的值不超过n的斐波那契数列,求值为偶数的项的和。
- Codeforce Round #438 C.Bus(贪心)
- Mathematical Morphology —— Path Operator
- java入门第三季--图书馆借书系统
- [蓝书/Ch5] The K-League UVALive
- 打印机管理网站(Java Web+Bootstrap)
- HDU2767 Proving Equivalences 解题报告【tarjan缩点】
- 几种保持登录状态的方式
- Linux中安装配置arm-2009q3方法
- 【NOJ】[1000] A+B Problem