201812-2 Xiaoming is out of school

Background of
  the subject Guangming District, where the middle school affiliated to Handong University of Political Science and Law, recently implemented a smart city project called "Smart Light". Specific to the transportation field, through the "smart light" terminal, you can see the status of all traffic lights in the bright area at this moment. Xiaoming's school also installed a "wisdom light" terminal. Xiaoming wanted to use the information given by this terminal to estimate the time he would go home after school.
Problem description
  When school was over, Xiaoming had already planned his own route home and was able to predict the time to pass each section. At the same time, Xiaoming saw the indication status of all the traffic lights passing on the road at the time of departure through the "wisdom light" terminal installed in the school. Please help me calculate the time it takes for Xiaoming to go home this time.
Input format
  The first line of input contains three positive integers r, y, g separated by spaces, indicating the setting of traffic lights. None of these three numbers exceed 106.
  The second line of the input contains a positive integer n, which represents the total number of road segments and the number of traffic lights passing by Xiao Ming.
  The next n lines each contain two integers k and t separated by spaces. k = 0 means that after a period of time, it will take t seconds, where t does not exceed 106; when k = 1, 2, and 3, it means the departure time, and the traffic lights here are red, yellow, and green , And the number displayed on the countdown display card is t, where t will not exceed r, y, and g, respectively.
Output format
  outputs a number indicating the time spent by Xiaoming going home from school this time.
Sample input
30 3 30
8
0 10
1 5
0 11
2 2
0 6
0 3
3 10
0 3
Sample output
46
Sample Description
  Xiaoming first passed the first section of road, which took 10 seconds. The first traffic light was a red light when leaving, with 5 seconds left; when Xiao Ming arrived at the intersection, the traffic light had turned into a green light, and there was no need to wait to pass directly. Next, it took 11 seconds to cross the second section of road. The second traffic light was a yellow light when leaving, with two seconds left; when Xiao Ming reached the intersection, the traffic light had changed to a red light with 11 seconds left. After passing the third and fourth sections, it took 9 seconds. The third traffic light was a green light when starting, with 10 seconds left; when Xiao Ming reached the intersection, the traffic light had changed to a red light with two seconds left. Next, it took 3 seconds to pass the last road. Total 10 + 11 + 11 + 9 + 2 + 3 = 46 seconds.
Evaluation use case size and agreement
  Some test points have special properties:
  * There are no signal lights in the first 2 test points.
  Input data scale of test points:
  * The first 6 test points guarantee n ≤ 103.
  * All test points guarantee n ≤ 105.

#include <iostream>
using namespace std;

int main()
{
	int r,y,g;
	cin>>r>>y>>g;
	int n;
	cin>>n;
	long long total=0;
	while(n--)
	{
		int k,t;
		cin>>k>>t;
		if(k==0)
		{
			total+=t;
		}
		if(k==1)
		{
			int m=(total+r-t+y)%(r+y+g);
			if(m<r+y)
			{
				total+=r+y-m;
			}
		}
		if(k==2)
		{
			int m=(total+y-t)%(r+y+g);
			if(m<r+y)
			{
				total+=r+y-m;
			}
		}
		if(k==3)
		{
			int m=(total+r-t+y+g)%(r+y+g);
			if(m<r+y)
			{
				total+=r+y-m;
			}
		}
	}
	printf("%lld\n",total);
	return 0;
}

Published 30 original articles · won 9 · visited 1312

Guess you like

Origin blog.csdn.net/weixin_43625164/article/details/105434983