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 ...
随机推荐
- 关闭防火墙,selinux,交互式设置IP的脚本
脚本内容: #!/bin/bash # ens=$(cat /proc/net/dev | awk '{if($2>0 && NR > 2) print substr($1 ...
- 【转】Syncthing – 数据同步利器---自己的网盘,详细安装配置指南,内网使用,发现服务器配置
Syncthing – 数据同步利器---自己的网盘,详细安装配置指南,内网使用,发现服务器配置 原贴:https://www.cnblogs.com/jackadam/p/8568833.html ...
- mybatis的逆向工程和中文注解
由于MyBatis Generator自带了生成注释的功能,但是,是英文的而且生成的根本无法理解,所以可以通过,修改他的源码来实现生成中文的注释,具体方式有以下几种: 1) 自定义CommentGen ...
- react优缺点
优点: 1.面向组件,方便组件的复用. 2.从操作dom改为操作state. 缺点: 1.html和javascript较高耦合,不方便分工开发. 2.当一个页面中两处元素组件有相关性时,父组件会非常 ...
- 和2018年年初做管理系统的不同(vuex)
从2017年底开始做公司批改后台系统(服务内部人员对熊猫小课用户的作业进行批改.对批改员工资结算等)到教务系统(服务于内部人员对熊猫小课等移动端产品的内容进行配置等).ai-boss系统(服务于内部人 ...
- 学习python第三天
变量的命名规范 1.只能有 字母 数字 及_组成 2.不能以数字开头 3.避免与系统关键词重名:重名不会报错,但系统的功能就被自定义的功能屏蔽掉了(严重不建议这样做) 4._开头的变量都有特出含义 5 ...
- 7.4 electirc.c -- 计算电费
// 7.4 electirc.c -- 计算电费 #include <stdio.h> #define RATE1 0.13230 // 首次使用 360 kwh 的费率 #define ...
- js中正则表达式使用
js中使用正则表达式,除了了解正则表达式基本的匹配规则外.还需要了解下面的基本的知识: python,js,groovy这些脚本语言都有在线调试的网站,可以在线测试是否有语法错误,用起来也很方便. v ...
- idea中使用MyBatis Generator
1.新建maven项目 2.新建Generator配置文件 generator_config.xml <?xml version="1.0" encoding="U ...
- Windows下通过pip安装PyTorch 0.4.0 import报错
问题:通过pip安装PyTorch 0.4.0成功,但是import时报错. import torch File "D:\Python\Python36\lib\site-packages ...