작성일 :

문제 링크

8760번 - Schronisko

설명

W×K 격자에 1×2 도미노를 최대로 배치할 때 수용 가능한 관광객 수를 구하는 문제입니다.


접근법

1×2 도미노로 덮을 수 있는 최대 개수는 전체 칸 수의 절반입니다.

따라서 W × K / 2를 정수 나눗셈으로 계산하여 출력합니다.



Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
using System;

class Program {
  static void Main() {
    var t = int.Parse(Console.ReadLine()!);
    while (t-- > 0) {
      var p = Array.ConvertAll(Console.ReadLine()!.Split(), int.Parse);
      var w = p[0]; var k = p[1];
      Console.WriteLine(w * k / 2);
    }
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int t; cin >> t;
  while (t--) {
    int w, k; cin >> w >> k;
    cout << (w * k) / 2 << "\n";
  }

  return 0;
}