\(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. Go:闭包

    闭包就是一个函数和与其相关的引用环境组合的一个整体(实体). package main import "fmt" func add() func(int) int { i := 0 ...

  2. Django 缓存之配置Redis

    一.cache介绍 由于Django是动态网站,所有每次请求均会去数据进行相应的操作,当程序访问量大时,耗时必然会更加明显,最简单解决方式是使用:缓存. 缓存工作原理:缓存是将一些常用的数据保存内存或 ...

  3. swing中的按钮事件

    package pack2; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax ...

  4. gnuplot examples

    xy plot #set terminal jpeg #set output 'alfa.jpg' set terminal postscript eps font 24 set out 'U_vs_ ...

  5. 【09】AngularJS 表格

    AngularJS 表格 ng-repeat 指令可以完美的显示表格. 在表格中显示数据 使用 angular 显示表格是非常简单的: <div ng-app="myApp" ...

  6. Maven学习总结(31)——Maven坐标详解

    Maven的一个核心的作用就是管理项目的依赖,引入我们所需的各种jar包等.为了能自动化的解析任何一个Java构件,Maven必须将这些Jar包或者其他资源进行唯一标识,这是管理项目的依赖的基础,也就 ...

  7. HUST 1214 Cubic-free numbers II

    Cubic-free numbers II Time Limit: 10000ms Memory Limit: 131072KB This problem will be judged on HUST ...

  8. RabbitMQ-高级特性(六)

    存储机制 待... 消息结构 惰性队列 惰性队列会尽可能将消息存入到磁盘中,消费者消费相应的消息才会加载到内存,它可以支持更长的队列 默认情况下生产者消息会尽可能存储到内存中就算设置持久化消息 也会再 ...

  9. R - Milking Time DP

    Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that sh ...

  10. androidannotations的background和UiThread配合使用參考

    简单介绍 androidannotations在开发中的代码规范思考:(MVC思考)时间太紧,先贴代码: Activity的代码: package edu.njupt.zhb.main; import ...