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. vs单独调试dll

    用生成好的exe单独调试dll,右键项目属性->调试->命令->选择exe

  2. update_engine-DownloadAction(二)

    在update_engine-DownloadAction(一)中对DownloadAction介绍到了DeltaPerformer的Write方法.下面开始介绍Write方法. src/system ...

  3. MongoDB Sharding分片 shell 脚本

    #!/bin/sh CONFIG_NAME=$ CONFIG_PORT=$ SERIAL_NUM=$ STORAGE_HOME=$ if [ ! -n "$CONFIG_NAME" ...

  4. EF Like

    public static class EdmxExtensions { [EdmFunction("YourEFModel", "String_Like")] ...

  5. HashTable & HashMap & ConcurrentHashMap 原理与区别

    一.三者的区别     HashTable HashMap ConcurrentHashMap 底层数据结构 数组+链表 数组+链表 数组+链表 key可为空 否 是 否 value可为空 否 是 否 ...

  6. 2018/12/19 20:55:58 螺纹钢豆粕PTA

    螺纹钢M5中枢上升到M30级别,感觉向上的可能高..可是没有好的开仓位,那就不用硬要开仓,耐心等待自己熟悉的信号: PTA M5中枢扩展为M30中枢,目前M30向下一笔没结束: 豆粕等待当前日线下跌结 ...

  7. 刘志梅201771010115.《面向对象程序设计(java)》第十四周学习总结

    实验十四  Swing图形界面组件 实验时间 20178-11-29 1.实验目的与要求 (1)设计模式:反复使用.经过分类编目的.代码设计经验的总结. 在Alexander的模式分类和软件模式的分类 ...

  8. python初识,变量,条件判断语句,基本数据类型,while循环语句

    python文件后缀可以是任意,但是导入模块时不用.py后缀时会报错 python文件的两种执行方式: python解释器 python文件路径 进入python解释权,事实获取执行结果 在Linux ...

  9. linux ssl证书配置(apache)

    1. 前提是 已通过第三方 申请到 .crt .key 和 .ca-bundle 文件 2. 将三个文件拷贝到linux服务器上 任意一个指定的目录 3. 找到要编辑的apache配置 Apache主 ...

  10. codeblock字体问题

    有的时候在codeblock中打下划线,会显示空格, 这个时候可以修改一下字体 settings->editor->editor settings最上面的fonts框中选择choose,然 ...