CodeForces - 864C-Bus-(模拟加油站问题)
https://vjudge.net/problem/CodeForces-864C
题意:两地之间有个加油站,往返走k个单程,最少加油多少次。
大佬几十行代码就解决,我却要用一百多行的if语句模拟解决。
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<string>
#include<queue>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std; ll a,b,f,k;
ll one,two;///加油站左边路程为one,右边路程为two
ll t;
ll nowb;
ll sum; int main()
{
while(scanf("%lld %lld %lld %lld",&a,&b,&f,&k)!=EOF)
{
one=f;
two=a-f;
nowb=b; ///当前体力
sum=a*k; ///总路程
t=; ///补充体力次数
ll i; ///当前走了多少路程
bool flag=true; ///能否走到
int now=; ///now表示方向,1为右,-1为左 for(i=;i<sum;)///不加等于,不要i++
{
if(i==)///刚出发
{
if(nowb>=one)///能走到加油站
{
i+=one;
nowb-=one;
}
else///否则直接凉
{
flag=false;
break;
}
}
else if( k% && i==sum-two)///奇数次,最后向右,最后要走two这一段
{
if(nowb>=two)///走得到
{
i+=two;
nowb-=two;
}
else///走不到,加完再看能不能到
{
nowb=b;
t++;
if(nowb>=two)
{
i+=two;
nowb-=two;
}
else
{
flag=false;
break;
}
}
}
else if( k%== && i==sum-one)///偶数次,最后向左,最后要走one这一段
{
if(nowb>=one)
{
i+=one;
nowb-=one;
}
else
{
nowb=b;
t++;
if(nowb>=one)
{
i+=one;
nowb-=one;
}
else
{
flag=false;
break;
}
}
}
else ///中间跑路,走两段one或者two
{
if(now==)///往右跑
{
if(nowb>=*two)///跑得到,减油,改方向
{
i+=*two;
nowb-=*two;
now=-;
}
else ///否则,加油
{
t++;
nowb=b;
if(nowb>=*two)///加完看能不能跑到
{
i+=*two;
nowb-=*two;
now=-;
}
else
{
flag=false;
break;
}
}
}
else ///往左跑
{
if(nowb>=*one)
{
i+=*one;
nowb-=*one;
now=;
}
else ///否则,加油
{
t++;
nowb=b;
if(nowb>=*one)///加完看能不能跑到
{
i+=*one;
nowb-=*one;
now=;
}
else
{
flag=false;
break;
}
}
} }
}
if(flag)
printf("%d\n",t);
else
printf("-1\n");
}
return ;
}
CodeForces - 864C-Bus-(模拟加油站问题)的更多相关文章
- [Codeforces 864C]Bus
Description A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After ...
- 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 ...
- Educational Codeforces Round 11B. Seating On Bus 模拟
地址:http://codeforces.com/contest/660/problem/B 题目: B. Seating On Bus time limit per test 1 second me ...
- 【模拟】Codeforces 711A Bus to Udayland
题目链接: http://codeforces.com/problemset/problem/711/A 题目大意: N个字符串,每个字符串5位,找到第一个出现两个OO的并改成++输出YES和改后字符 ...
- codeforces 660B B. Seating On Bus(模拟)
题目链接: B. Seating On Bus time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces 389B(十字模拟)
Fox and Cross Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submi ...
- codeforces 591B Rebranding (模拟)
Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...
- Codeforces 626B Cards(模拟+规律)
B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...
- Codeforces 631C. Report 模拟
C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
随机推荐
- VS调试快捷键配置更改
VS进行调试时,默认情况下需按下Fn+F5等组合按键,手短的用起来很不便利 如何去掉组合键只按下F5? 解决:即按下Fn+Esc,然后就可以直接按下F1-F12使用VS的快捷键,如果想回到组合键也是同 ...
- php7带来的性能升级
前言本文是一篇讲座听后+后续研究的总结. 话说当年追时髦,php7一出就给电脑立马装上了,php5和php7共存,也是立马写了个超级耗时间的循环脚本测了一番,确实php7给力很多,然后也是注意了一些新 ...
- CentOS 6 update curl
touch /etc/yum.repos.d/city-fan.repo vi /etc/yum.repos.d/city-fan.repo add the following: [CityFan] ...
- 学会学习:高效学习方式(使用vscode-snippet有感)
入职以来我们团队一直都在使用vscode编辑器,后来也有人开始使用webstorm.很久之前我突然为每天重复的编写.vue文件里面的export.<script lang="scss& ...
- MTSC2018 | 确认过眼神,在这里能遇见Google、阿里、百度......
MTSC2018部分Topic曝光啦 Google,阿里,百度,美团,小米,360,网易等公司是如何将技术转化为现实生产力,提高工作效率的?离开Saucelab的Jonathan又是如何规划Appiu ...
- Elasticsearch-6.7.0系列-Joyce博客总目录
官方英文文档地址:https://www.elastic.co/guide/index.html Elasticsearch博客目录 Elasticsearch-6.7.0系列(一)9200端口 . ...
- Butterknife--Android Butterknife使用方法总结(转)
原文链接:http://blog.csdn.net/donkor_/article/details/77879630 前言: ButterKnife是一个专注于Android系统的View注入框架,以 ...
- [UE4]快速移动,给单位向量加一个力
一.(Vector_End- Vector_Start ).Normalize,获取从起始位置指向目标位置的单位向量. 二.给单位向量乘以一个浮点数,即给向量加一个力,是往向量方向移动 每一帧往目标点 ...
- spring从服务器磁盘读取图片,然后显示于前端页面上
需求是,前台通过传参,确定唯一图片,然后后台在服务器磁盘中读取该图片,然后显示于前台页面上. 后台代码: @RequestMapping("unit/bill/showeinvoice&qu ...
- Windows下访问控制管理
参考URL: https://blog.csdn.net/u011801161/article/details/45567289 http://blog.nsfocus.net/analysis-wi ...