#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
ll r, y, g;
// from state k to green
ll wait_for(ll k, ll p, ll t){
ll wait_time = 0;
//time pass total rounds
p = p % (r+y+g);
// begin red
if (k == 1){
// wait r
if (p < t) wait_time = t-p;
// g
else if (p < t+g) wait_time = 0;
// pass g, wait y r
else wait_time = t-p+g+y+r;
}
//begin yellow
else if (k == 2){
// wait y r
if (p < t+r) wait_time = t-p+r;
// g
else if (p < t+r+g) wait_time = 0;
// wait y r
else wait_time = t-p+r+g+y+r;
}
//begin green
else {
// g
if (p < t) wait_time = 0;
// wait y r or r
else if (p < t+y+r) wait_time = t-p+y+r;
// g
else wait_time = 0;
}
return wait_time;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
ll n, k, t, sum = 0;
cin >> r >> y >> g >> n;
while (n--){
cin >> k >> t;
// pass road
if (!k) sum += t;
// have light
else sum += wait_for(k, sum, t);
}
cout << sum;
return 0;
}
【CSP】201812-2 小明放学 模拟
最新推荐文章于 2021-10-27 12:36:58 发布