CCF CSP-201812-2 小明放学(C++)

CCF CSP-201812-2 小明放学(C++)

#include <cstdio>

int r, y, g;

int wait(long long t){
	int sumtime = r + y+ g;
	t = t%=sumtime;
	
	if(t < r){
		return r - t;
	}else if(t < r+g){
		return 0;
	}else{
		return sumtime - t + r;
	}
}

int main(){
	scanf("%d %d %d", &r, &y, &g);
	
	int n;
	scanf("%d", &n);
	
	long long sum = 0;
	for(int i=0; i<n; i++){
		int k, t;
		scanf("%d %d", &k, &t);
		
		if(k == 0){
			sum += t;
		}else if(k == 1){
			long long temp = sum + r - t;
			
			int time = wait(temp);
			sum += time;
		}else if(k == 2){
			long long temp = sum + r + g + y - t;
			
			int time = wait(temp);
			sum += time;
		}else if(k == 3){
			long long temp = sum + r + g - t;
			
			int time = wait(temp);
			sum += time;
		}
	}
	
	printf("%lld", sum);
	
	return 0;
}
上一篇:CCF python 201709-2 公共钥匙盒


下一篇:CCF CSP201509-1数列分段(c++100)