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-(模拟加油站问题)的更多相关文章

  1. [Codeforces 864C]Bus

    Description A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After ...

  2. 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 ...

  3. 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 ...

  4. 【模拟】Codeforces 711A Bus to Udayland

    题目链接: http://codeforces.com/problemset/problem/711/A 题目大意: N个字符串,每个字符串5位,找到第一个出现两个OO的并改成++输出YES和改后字符 ...

  5. codeforces 660B B. Seating On Bus(模拟)

    题目链接: B. Seating On Bus time limit per test 1 second memory limit per test 256 megabytes input stand ...

  6. Codeforces 389B(十字模拟)

    Fox and Cross Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submi ...

  7. codeforces 591B Rebranding (模拟)

    Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...

  8. Codeforces 626B Cards(模拟+规律)

    B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...

  9. Codeforces 631C. Report 模拟

    C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

随机推荐

  1. Web高级 网站安全

    1. SQL注入 虽然现在SQL注入发生的情况总的来说越来越少,还是提二句.关于什么是SQL注入大家都知道就不多说了. 1.1 原理 我们在做前端页面的时候,少不了会又各种输入框,然后通过GET或者P ...

  2. 7.12 vowels.c 程序

    7.12 vowels.c 程序 #vowels.c -- 使用多重标签 #include <stdio.h> int main(void) { char ch; int a_ct, e_ ...

  3. Mysql 分组选择

    Mysql 分组选择 在其他的数据库中我们遇到分组选择的问题时,比如在分组中计算前10名的平均分 我们可以使用row_number()over() 比较方便的得到. 但是在mysql中,问题就被抛了出 ...

  4. 用antd和webview打造一款大数据客户端程序

    要想提高工作效率,必须得有好的工具.大数据有很多组件,但是邪了门儿的就是,竟然没有一个好用的客户端程序. 没办法,我只好用antd+webview自己做了一款跨平台的桌面应用. 先看下效果. 这是gi ...

  5. 使用Git Bash从Git上下载代码到本地以及上传代码到码云Git

    前提是在码云上已经新建一个空的项目,可参考:https://www.cnblogs.com/babysbreath/p/9170455.html 1.新建一个目录,存放下载下来的项目,我在D盘新建了一 ...

  6. WordPress版微信小程序3.5版发布

    最近花时间对WordPress版微信小程序做了一些完善和调整,修复不少程序的问题.一个程序的完善是持续和渐进的,没有最好,只有更完善.虽然会采纳一些用户的建议和意见,但我会从一个产品角度去考虑,哪些功 ...

  7. mysql集群搭建--韩国庆

    按照我给大家提供的步骤,一步一步来,你就能配好mysql集群环境 什么是mycat 简单的说,MyCAT就是: •一个彻底开源的,面向企业应用开发的“大数据库集群” •支持事务.ACID.可以替代My ...

  8. JavaWeb——关于RequestDispatcher的原理

    RequestDispatcher简介 RequestDispatcher 代表请求的派发者.它有2个动作:forward 和 include .客户端对于任何一个请求,可以根据业务逻辑需要,选择不同 ...

  9. debian apache2 多端口对应多文件 虚拟端口配置

    apache2单IP多端口创建虚拟站点如下: 1.转到配制目录虚拟站点配制目录 cd /etc/apache2/ ​ 2.配置新增多的端口 编辑上级目录中的端口配制文件sudo gedit ports ...

  10. DatetimeHelper,时间帮助类

    public static class DateTimeEx { /// <summary> /// 得到中文形式的日期 /// </summary> /// <para ...