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 ...
随机推荐
- 多线程shell脚本检测主机存活
局域网中分了很多网段,而IP地址使用情况也未知,前期也没有规划和记录,当新的主机需要使用固定IP的时候,能否第一时间知道哪个IP空闲就显得很重要了,如果一个一个去ping的话太浪费时间. 这里分享一个 ...
- php使用insert语句动态添加用户
<html> <head> <title>Adding User</title> </head> <body> <h2&g ...
- Centos7 kernel 内核升级 GPU显卡驱动程序编译安装
1.NVIDIA官网下载相关显卡驱动 #在服务器上查看网卡型号 lspci -mm | grep NVIDIA #在NVIDIA官网下载相应型号驱动程序 https://www.geforce.c ...
- JVM-垃圾收集算法
新生代:复制算法,IBM研究过,约98%对象是“朝生夕死”,所以不需要按照1:1来划分:HotSpot中默认是8:1:1,即每次新生代可用空间为90%,只有10%会被“浪费”, 当Survivor空间 ...
- SpringBoot启动源码探究---listeners.starting()
1.首先调用starting()方法,其内部是一个对所有listener的starting()调用的for循环,然后每个listener调用另一个starting方法,其内部调用multicastEv ...
- [蓝桥杯]PREV-25.历届试题_城市建设
问题描述 栋栋居住在一个繁华的C市中,然而,这个城市的道路大都年久失修.市长准备重新修一些路以方便市民,于是找到了栋栋,希望栋栋能帮助他. C市中有n个比较重要的地点,市长希望这些地点重点被考虑.现在 ...
- C# 6.0:Null – Conditional 操作符
在引入nameof操作符的同时,C# 6.0 还引入了Null-Conditional操作符.它使开发者可以检查object引用链中的null值.这个null-conditional 操作符写作&qu ...
- 你云我云•兄弟夜谈会 第二季 5G
0. 概况 时间:2019年1月29日 21:30~23:15 兄弟团:金孝(主持人).肖力.楼炜.张亮.孙杰.熊.世民 主题:5G 1. 5G超简单科普 金孝首先对大家做了超简单5G科普.5G 是第 ...
- C++primer第一章(部分)
1.4.2 for 语句 for (init-statement; condition; expression) statement; step1:初始化 step2:判断条件,为真则执行循体:为假则 ...
- 2018/12/20 20:52:42 螺纹钢PTA豆粕
如期向上,但是一点办法没有:没有好的入场位,不做不算错,面对诱惑不动如山也是一种修养,今晚看M5有没有3买,有的话可以看情况考虑要不要进场 PTA M30向下一笔过程中,等待M30当前一笔下跌结束,可 ...