Codeforces Round #436 (Div. 2) C. Bus
http://codeforces.com/contest/864/problem/C
题意:
坐标轴上有x = 0和 x = a两点,汽车从0到a之后掉头返回,从a到0之后又掉头驶向a。。。从0到a或者从a到0叫做一次旅行。汽车的油箱的容量为b,行驶1单位长度消耗的油量为1单位,在x = f处有一个加油站,可以把油加满。
现在,汽车位于x = 0处,将要进行k次旅行,开始汽车的油箱是满的,问至少要加多少次油才能走完全程,或者不可能时输出“-1”。
思路:
可以把汽车的旅行看成是一直向前的,那么旅途中就有k个加油站,我们首先保证能够走到第一个加油站,之后根据贪心原则,走不到下一个加油站就在当前加油站加油,加了油之后都走不到的话,那就永远没有办法走到了。。。
最后再判断一下是否可以走完最后一个加油站到终点的路程即可。
代码:
#include <stdio.h> int main()
{
long long a,b,f,k; scanf("%lld%lld%lld%lld",&a,&b,&f,&k); long long now = b; long long ans = ; if (now < f) printf("-1\n");
else
{
now -= f;
for (int i = ;i < k;i++)
{
long long d = (i & ) ? (a - f) : f; d <<= ; if (d > now) ans++,now = b;
if (d > now)
{
printf("-1\n");
return ;
} now -= d;
} long long d = (k & ) ? a - f : f; if (d > now) ans++,now = b;
if (d > now) printf("-1\n");
else printf("%d\n",ans);
} return ;
}
Codeforces Round #436 (Div. 2) C. Bus的更多相关文章
- Codeforces Round #436 (Div. 2)C. Bus 模拟
C. Bus time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input out ...
- Codeforces Round #436 (Div. 2)【A、B、C、D、E】
Codeforces Round #436 (Div. 2) 敲出一身冷汗...感觉自己宛如智障:( codeforces 864 A. Fair Game[水] 题意:已知n为偶数,有n张卡片,每张 ...
- Codeforces Round #369 (Div. 2) A. Bus to Udayland 水题
A. Bus to Udayland 题目连接: http://www.codeforces.com/contest/711/problem/A Description ZS the Coder an ...
- Codeforces Round #484 (Div. 2) B. Bus of Characters(STL+贪心)982B
原博主:https://blog.csdn.net/amovement/article/details/80358962 B. Bus of Characters time limit per tes ...
- Codeforces Round #369 (Div. 2) A. Bus to Udayland (水题)
Bus to Udayland 题目链接: http://codeforces.com/contest/711/problem/A Description ZS the Coder and Chris ...
- Codeforces Round #436 (Div. 2) E. Fire
http://codeforces.com/contest/864/problem/E 题意: 有一堆物品,每个物品有3个属性,需要的时间,失效的时间(一开始)和价值.只能一件一件的选择物品(即在选择 ...
- Codeforces Round #436 (Div. 2)
http://codeforces.com/contest/864 第一次打cf的月赛-- A 题意:给你一个数列,问你能不能保证里面只有两种数且个数相等.2<=n<=100,1<= ...
- Codeforces Round #436 (Div. 2) D. Make a Permutation!
http://codeforces.com/contest/864/problem/D 题意: 给出n和n个数(ai <= n),要求改变其中某些数,使得这n个数为1到n的一个排列,首先保证修改 ...
- Codeforces Round #436 (Div. 2) B. Polycarp and Letters
http://codeforces.com/contest/864/problem/B 题意: 给出一个字符串,要求找到一个集合S,使得从S中选出的所有数,在这些数的位置上的字母全部为小写且是不同的字 ...
随机推荐
- 转python爬虫:BeautifulSoup 使用select方法详解
1 html = """ 2 <html><head><title>The Dormouse's story</title> ...
- Intellj IDEA常用快捷键
1.生成Getter.Setter方法:Alt + Insert
- 2017年9月3日 Spring及Mybatis中连接数据库的不同方式
连接数据库用spring和mybatis中使用的方法可以不同,mybaits可以不用写数据库的配置文件 Spring的连接方法 <!-- 读取属性文件(.properties)的内容 --> ...
- [2012-06-18]awk利用关联数组合并记录
问题源起:http://bbs.chinaunix.net/thread-3753784-1-1.html 代码如下 {% capture text %} $awk '{if(!a[$1]){a[$1 ...
- NOSQL EYE开源
简介 NOSQL数据库监控工具,目前实现了对Redis.MongoDB的监控功能. 功能列表 演示地址 http://106.14.181.95:7004 登录用户名.密码:admin/admin ...
- Ext.grid.EditorGridPanel分页和查看全部
在gridPanel添加查看全部数据按钮,必须使得每页显示的数量pageSize为总条数,那么总页数就只会有一页. 1.获取store数据的总条数 var totalCount = grid.getS ...
- py2 HTMLTestRunner报告
直接上代码吧. #coding:utf-8 #__author__ = 'carry' import unittest,HTMLTestRunner class Hello(unittest.Test ...
- MySQL的JOIN(一):用法
JOIN的含义就如英文单词"join"一样,连接两张表,大致分为内连接,外连接,右连接,左连接,自然连接.这里描述先甩出一张用烂了的图,然后插入测试数据. CREATE TABLE ...
- Mysql中使用聚合函数对null值的处理
平时因为对于数据库研习的不深,所以在面试的时候问了一些平常遇到过的问题居然没法很肯定地回答出来,实在让自己很恼怒! 这次让我记忆深刻的一个问题是: 在mysql中使用聚合函数的时候比如avg(t),t ...
- Maven(四)之Maven在IntelliJ IDEA的配置与使用
前面介绍了Maven的一些基本知识,这一篇讲一下在IntelliJ IDEA配置和使用Maven 一.配置Maven 在File->Settings->Build,Execution,De ...