$P5269 欧稳欧再次学车$
\(problem\)
哇 看各位巨佬都来发\(T1\)的题解 我也来发一篇。(别的题目不会别瞎bb)
题目大意就是
\(T\) 秒 能走多少路程
第一行六个整数 \(T,N,L,R,X,K\)
接下来 \(T\) 行,每行两个整数 \(x,y\) 表示这一秒的操作。
我们设档为\(D\),转速为\(V\)
首先 \(D = 1\) ,\(V = L\) 。
\(x == 1\) \(D++\),\(V=L\)
\(x == 2\) \(D--\),\(V=R\)
\(y == 0\) \(V+=X\)
\(V > R\) 则 \(V=R\)(即\(V=min(V+X,R)\))
连续\(K\)秒 \(V=R\) 则停止。
得出
if(V == R) cnt ++ ;
if(V != R) cnt = 0 ;
if(cnt == K) break ;
特别注意的一点 是 特判\(-1\)
即
if(D == N+1 or D == 0) return printf("-1"),0;
完整代码如下。
//完整代码
#include <bits/stdc++.h>
using namespace std;
typedef long long LL ;
inline LL In() { LL res(0),f(1); register char c ;
while(isspace(c=getchar())) ; c == '-'? f = -1 , c = getchar() : 0 ;
while(res = (res << 1) + (res << 3) + (c & 15) , isdigit(c=getchar())) ;
return res * f ;
}
LL T , N , L , R , X , K ;
LL D , V ;
signed main () {
T = In() ; N = In() ; L = In() ; R = In() ; X = In() ; K = In() ;
D = 1 , V = L ;
LL ans = 0 ;
LL cnt = 0 ;
for(register int i = 1 ; i <= T ; i++) {
int x , y ;
x = In() , y = In() ;
if(x == 0) D ++ , V = L ;
if(x == 1) D -- , V = R ;
if(D == N+1 or D == 0) return printf("-1"),0;
if(y) V = V+X>R?R:V+X;
if(V == R) cnt ++ ;
if(V != R) cnt = 0 ;
ans += D * V ;
if(cnt == K) break ;
}
cout << ans ;
return 0 ;
}
随机推荐
- Django ContentType内置组件
一.引出问题 假如有这两张表,它们中的课程可能价格不一样.周期不一样.等等...不一样...,现在有一张价格策略表,怎么就用一张表报保存它们之间不同的数据呢? 可能你会这样: 确实是行!但是,如果有很 ...
- PHP 生成器Generators的入门理解和学习
什么是生成器Generators 生成器允许你在 foreach 代码块中写代码来迭代一组数据而不需要在内存中创建一个数组, 那会使你的内存达到上限,或者会占据可观的处理时间.相反,你可以写一个生成器 ...
- TensorFlow — 相关 API
TensorFlow — 相关 API TensorFlow 相关函数理解 任务时间:时间未知 tf.truncated_normal truncated_normal( shape, mean=0. ...
- NOIP2018提高组省一冲奖班模测训练(一)
比赛链接 https://www.51nod.com/contest/problemList.html#!contestId=72&randomCode=147206 这次考试的题非常有质量 ...
- python整数转ASCII码
# *-* coding:utf-8 *-* import binascii data = [1441465642, 251096121, -870437532, -944322827, 647240 ...
- vim高亮显示当前行列
vim高亮显示当前行: set cursorline vim高亮显示当前列: set cursorcolumn
- java 远程调用
1.webservice (soap+http) -aixs -axis2 -xfire—>cxf 2.webservice问题 -基于xml,xml效率,(数据传输效率,xml序列化效率) - ...
- H - Tickets
Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this is really a ...
- System.out.print()思考?
System.out.print()思考 问题? System.out.pritln(); 中是包名.类名.方法名吗? 解释: Syste ...
- SiteMesh2-sitemesh.xml的PageDecoratorMapper映射器的用法
继上一章http://www.cnblogs.com/EasonJim/p/7083165.html中使用的例子中,是通过decorators.xml文件通过URL匹配进行转换的. 而下面这种方法是通 ...