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. error: Cannot find OpenSSL's <evp.h> Mac

    问题 mac安装php需要openssl ./configure –with-openssl 报错 error: Cannot find OpenSSL’s 解决 brew install opens ...

  2. Ubuntu 18.04 使用Systemd管理MySQL 5.6

    转自:https://blog.csdn.net/skykingf/article/details/45225981 如何用Systemd管理 general 包安装的MySQL呢? 首先看看yum安 ...

  3. 【C++】const & 指针

    https://blog.csdn.net/qq_21808961/article/details/78401950

  4. APS技术中的多目标规划问题

    在进行APS(高级计划与排程)系统开发时,绝大多数情况下是需要考虑多目标的.但面对多目标问题进行规划求解时,我们往往极容易因处理方法不当,而影响输出结果,令结果与用户期望产生较大差别.事实上很多时候用 ...

  5. django orm 管理器 objects

    给某张表的管理器重命名 class User(models.Model): name = models.CharField(max_length=100) people = models.Manage ...

  6. 工控随笔_07_西门子_WinCC利用命令行实现操作log日志

    在WinCC中可以通过报警纪录来实现操作员纪录,这个需要WinCC的消息系统进行组态和配置. 利用消息系统进行实现上诉功能不但复杂而且时间久啦也不方便查询.那么有没有一种简单的方法来 实现操作员纪录呢 ...

  7. EVM项目管理

    详细参照:https://zhuanlan.zhihu.com/p/33925657 报告日实际: 按预算完成 按原始cpi完成 按时完成

  8. Android Gradle Issue - Flutter / Dart

    解决 "Minimum supported Gradle version is 4.6. Current version is 3.3." I have a problem wit ...

  9. dotnet core调试docker下生成的dump文件

    最近公司预生产环境.net core应用的docker容器经常出现内存暴涨现象,有时会突然吃掉几个G,触发监控预警,造成容器重启. 分析了各种可能原因,修复了可能发生的内存泄露,经测试本地正常,但是发 ...

  10. mysql-5.7.20

    . 下载mysql- wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-i686.tar. ...