문제 : https://www.acmicpc.net/problem/18247


[알고리즘풀이]

N, M을 입력받고 N이 12보다 작거나 M이 4보다 작다면 L열 4석이 존재하지않으므로 -1을 출력하고,

아니라면 L열 4석의 번호를 출력하면 되므로 11개의 열 * M개의 석 + 4 를 출력하면 된다.

#include<iostream>

using namespace std;

int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t;
	cin >> t;
	while (t--) {
		int N, M;
		cin >> N >> M;
		if (N < 12 || M < 4) {
			cout << -1 << '\n';
		}
		else
			cout << 11 * M + 4 << '\n';
	}
	return 0;
}

 

+ Recent posts