\(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 ;
}

随机推荐

  1. 【04】AngularJS 表达式

    AngularJS 表达式 AngularJS 使用 表达式 把数据绑定到 HTML. AngularJS 表达式 AngularJS 表达式写在双大括号内:{{ expression }}. Ang ...

  2. 20170613NOIP模拟赛

    共3道题目,时间3小时 题目非原创,仅限校内交流使用 题目名称 Graph Incr Permutation 文件名 graph incr permutation 输入文件 graph.in incr ...

  3. Problem 2669

    Romantic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  4. about service in android

    注意:标红处! A Service is an application component representing either an application's desire to perform ...

  5. swift 2.0 语法 分支

    import UIKit // 注意: Swift中可以不写;号, 但是有一定的前提条件, 一行只有一句代码 //      如果一行有多句代码, 那么;还是必须写 // 注意: Swift变态的地方 ...

  6. Android 自己定义Activity基类

    我们在开发App的时候有时候碰到多个界面有一个共同点的时候.比方,都有同样的TitleBar.而且TitleBar能够设置显示的文字.TitleBar上的点击事件,假设给每个Activity都写一遍T ...

  7. Android CardView使用和导入出错问题

    Android CardView使用和导入出错问题 第一部分:导入Android CardView出错的问题. Android CardView是Android在support.v7包里面的一个vie ...

  8. oninput 中文输入

    使用 input 监听 input 中文输入,会被每次输入的字母打断,下面就解决这个问题 $('input') .off() .on('input',function(){ if($(this).pr ...

  9. Mysql常用索引及优化

    索引是帮助我们快速获取数据的数据结构.索引是在存储引擎中实现的,因此不同存储引擎的索引也不同.这里只介绍InnoDB存储索引所支持的BTree索引: 一.索引类型 为了方便举例子,先创建表person ...

  10. 【数学】mex是什么

    最近在看博弈论,SG函数,所以什么是mex呢 然后百度了一下得到: mex(S) 的值为集合 S 中没有出现过的最小自然数.例如,mex({1,2}) = 0.mex({0,1,2,3}) = 4