csp-小明放学
作者:互联网
其实本质就是时钟循环
#include<iostream>
#pragma warning(disable:4996)//忽略scanf不安全的警告
using namespace std;
unsigned long long r,y,g,st=0,t,n;//st=sum time 总时间 t为坐标轴映射时间
int traffic_signal_waiting_time(unsigned long long time, int signal){//r1 y2 g3 r->g->y
switch(signal){
case 1://红灯
t=r-time;break;//将time转换到坐标轴上映射 |____红r____|_____绿g_____|_____黄y_____|
case 2://黄灯
t=(r+y+g)-time;break;
case 3://绿灯
t=r+g-time;break;
}
t=(t+st)%(r+y+g);//和已经走过的时间做时钟运算
if(t<=r) return r-t;
else if(t<g+r) return 0;
else if(t<(r+y+g)) return (r+y+g)-t+r;
}
int main() {
scanf("%llu %llu %llu %llu", &r, &y, &g, &n);
unsigned long long b;int a;//a:信号灯标志 b:时间
for(int i=0;i<n;i++){
scanf("%d %llu",&a,&b);
if(a==0) st+=b;//走路
else st+=traffic_signal_waiting_time(b,a);//计算等待时间
}
cout<<st;
return 0;
}
标签:小明,_____,int,llu,st,long,time,csp,放学 来源: https://blog.csdn.net/Xuanyaz/article/details/120802422