解题思路:
灯的转换按如下方向,硬模拟,注意取模,注意数据范围10^(11)>2^(15)-1(int)(https://www.cnblogs.com/liuweimingcprogram/p/5840665.html)
解题代码:
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long LL;
int r,y,g,n;
LL time(int p,int t,LL sum){
int mod=r+g+y,temp;
if(p==0) sum+=t;
else if(p==1){
temp=(sum+(r-t))%mod;
if(temp>0&&temp<=r){
sum+=(LL)(r-temp);
}
else if(temp>r+g&&temp<=r+g+y){
sum+=(LL)((mod-temp)+r);
}
}
else if(p==3){
temp=(sum+(g-t))%mod;
if(temp>g&&temp<=g+y){
sum+=(LL)((g+y-temp)+r);
}
else if(temp>g+y&&temp<=g+y+r){
sum+=(LL)(mod-temp);
}
}
else if(p==2){
temp=(sum+(y-t))%mod;
if((temp>0&&temp<=y)||(temp>y&&temp<=(y+r))){
sum+=(LL)(r+y-temp);
}
}
return sum;
}
int main(){
cin>>r>>y>>g;
cin>>n;
int p,t;
LL sum=0;
while(n--){
cin>>p>>t;
sum=time(p,t,sum);
}
cout<<sum<<endl;
return 0;
}