#include <iostream>
#include <cmath>
typedef long long ll;
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int r,y,g,n,i,op,t;
ll ans =0,temp;
cin>>r>>y>>g>>n;
for(i = 0 ;i < n;i++)
{
cin>>op>>t;
if(op == 0)
{
ans+=t;
}else if(op == 1){
temp = ans;
temp-=t;
if(temp<0)//刚开始看到是红灯现在还没过去还是红灯
{
ans+=abs(temp);
}else{
//红灯的时间耗尽现在开始是 绿黄红
temp%=(r+y+g);
if(temp>=g&&temp<r+g+y)
ans+=r+g+y-temp;
}
}else if(op == 2){
temp = ans;
temp -=t;
if(temp<0)//刚开始看到是黄灯现在还没过去还是黄灯
{
ans+=abs(temp);
ans+=r;
}else{
//黄灯的时间耗尽现在开始是 红绿黄
temp%=(r+y+g);
if(temp>=0&&temp<r)
{
ans+=r - temp;
}else if(temp>=r+g&&temp<=r+g+y){
ans+=r+g+y-temp+r;
}
}
}else if(op == 3){
temp = ans;
temp -=t;
if(temp>=0){
//绿灯的时间耗尽现在开始是 黄红绿
temp%=(r+y+g);
if(temp>=0&&temp<y+r)
{
ans+=y+r-temp;
}
}
}
}
cout<<ans;
return 0;
}
201812-2 小明放学 c++
猜你喜欢
转载自blog.csdn.net/weixin_44142774/article/details/113707124
今日推荐
周排行