题解 P5269 【欧稳欧再次学车】
小黑AWM
2019-03-23 18:10:03
直接模拟:
注意要点观察到最大路程可能为$T * N * R$达到$10^{18}$故使用long long防止爆精度。其余无坑点。
代码:
```cpp
// luogu-judger-enable-o2
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<functional>
#include<cmath>
#include<vector>
#include<assert.h>
using namespace std;
using std::min;
using std::max;
using std::swap;
using std::sort;
using std::reverse;
using std::random_shuffle;
using std::lower_bound;
using std::upper_bound;
using std::unique;
using std::vector;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
#define type ll//看情况修改返回类型
inline char nc()
{
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline type read()
{
char ch=nc();type sum=0;
while(!(ch>='0'&&ch<='9'))ch=nc();
while(ch>='0'&&ch<='9')sum=(sum * 10)+ch-48,ch=nc();
return sum;
}
ll t, n, l, r, x, k, opt1, opt2, SUM, times, last, v;
int main(){
t = read(), n = read(), l = read(), r = read(), x = read(), k = read();
times = 1;
v = l;
for(int i = 1; i <= t; i++){
opt1 = read(), opt2 = read();
switch (opt1) {
case 0:
v = l;
if(times < n)
times++;
else{
printf("-1\n");
return 0;
}
break;
case 1:
v = r;
if(times > 1)
times--;
else{
printf("-1\n");
return 0;
}
break;
case 2:
break;
}
switch (opt2) {
case 0:
break;
case 1:
if(v+x <= r)
v += x;
else
v = r;
break;
}
if(v == r) last++;
else last = 0;
SUM += times*v;
//printf("x:%lld y:%lld\n", opt1, opt2);
//printf("time:%lld v:%lld times:%lld for:%lld length:%lld\n", i, v, times, last, SUM);
if(last == k)
break;
}
printf("%lld\n", SUM);
return 0;
}
```
可惜跑的不快