CCF认证:小明放学(满分代码)

 

 已满分通过

100分代码:

#include<iostream>
#include<string>
#include<set>
#include<queue>
#include<algorithm>
#include<map>
#include<vector>
#include<math.h>
#include<stack>
using namespace std;
long long int r, y, g, n;
long long int t = 0;
int time(int k,long long int t) {
	if (k==1) {
		if (t<=g) {
			return 0;
		}
		else if (t<=g+y) {
			return r + y + g - t;
		}
		else {
			return r + y + g - t;
		}
	}
	if (k==2) {
		if (t<=r) {
			return r - t;
		}
		else if (t<=r+g) {
			return 0;
		}
		else {
			return r + g + y - t + r;
		}
	}
	if (k==3) {
		if (t<=y) {
			return r + y - t;
		}
		else if (t<=r+y) {
			return r + y - t;
		}
		else {
			return 0;
		}
	}
}
int main(){
	cin >> r >> y >> g >> n;
	for (int i=0;i<n;i++) {
		int a , b;
		cin >>a>>b;
		if (a==0) {
			t = t + b;
			continue;
		}
		if(t-b>=0){
			t = t + time(a,(t-b)%(r+y+g));
		}
		else {
			if (a==1) {
				t = t + (b - t);
			}
			else if (a==2) {
				t = t + (r + y - t);
			}
			else {
				t = t + 0;
			}
		}
	}
	cout << t;
	return 0;
}


版权声明:本文为qq_51509115原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。