Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

자이의 프로그래밍

SWEA-1940 가랏! RC카! 본문

Algorithm/Cases-Study

SWEA-1940 가랏! RC카!

Xi_kor 2021. 3. 18. 20:36

a값을 입력받은 뒤 a값이 0이 아니면 b값도 입력받아야 하므로 b를 입력받았다.

a가 0이면 현재의 속도를 유지하므로 최종 달린 길이에 현재의 속도만큼을 더해주었다. (1초이므로)

a가 1이면 입력받은 속도만큼 가속한뒤 더해주었다.

a가 2이면 현재 속도보다 감속해야 할 속도가 더 큰 경우 0으로 속도를 맞춰주었고 그렇지 않은 경우에는 현재 속도를 입력받은 속도만큼 감속해 더해주었다. 

#include <iostream>
#include <queue>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

int main(){
	int test_case;
	cin>>test_case;
//	
	for(int T=1; T<=test_case; T++){
		int n;
		cin>>n;
		
		int nowspeed=0;
		int len=0;
		
		for(int j=0; j<n; j++){
			int a, b;
			cin>>a;
			if(a!=0) cin>>b;
			
			if(a==0){
				len+=nowspeed;
			}
			else if(a==1){
				nowspeed=nowspeed+b;
				len+=nowspeed;
			}
			else{
				if(nowspeed<b) nowspeed=0;
				else nowspeed=nowspeed-b;
				len+=nowspeed;
			}
		}
		cout<<"#"<<T<<" "<<len<<'\n';
	}
	return 0;
}

'Algorithm > Cases-Study' 카테고리의 다른 글

SWEA-1209 Sum  (0) 2021.03.25
SWEA-1213 String  (0) 2021.03.25
SWEA-1945 간단한 소인수분해  (0) 2021.03.18
SWEA-1946 간단한 압축풀기  (0) 2021.03.18
SWEA-1948 날짜 계산기  (0) 2021.03.18