๐Ÿ™‡โ€โ™€๏ธ[Silver III] Brattleship (Small) - 12147

๋ฌธ์ œ ๋งํฌ

์„ฑ๋Šฅ ์š”์•ฝ

๋ฉ”๋ชจ๋ฆฌ: 2020 KB, ์‹œ๊ฐ„: 0 ms

๋ถ„๋ฅ˜

์• ๋“œ ํ˜น, ๊ธฐํ•˜ํ•™, ์ˆ˜ํ•™

์ œ์ถœ ์ผ์ž

2024๋…„ 6์›” 10์ผ 19:50:21

๋ฌธ์ œ ์„ค๋ช…

You're about to play a simplified "battleship" game with your little brother. The board for this game is a rectangular grid with R rows and C columns. At the start of the game, you will close your eyes, and you will keep them closed until the end of the game. Your little brother will take a single rectangular 1 x W ship and place it horizontally somewhere on the board. The ship must always fit entirely on the board, with each cell of the ship occupying exactly one of the grid's cells, and it can never be rotated.

In each turn of the game, you name a cell on the board, and your little brother tells you whether that is a hit (one of the cells occupied by the ship) or a miss. (Your little brother doesn't say which part of the ship was hit -- just that the cell you named has a part of the ship in it.) You have perfect memory, and can keep track of all the information he has given you. Once you have named all of the cells occupied by the ship, the game is over (the ship is sunk), and your score is the number of turns taken. Your goal is to minimize your score.

Although the ship is not supposed to be moved once it is placed, you know that your little brother, who is a brat, plans to cheat by changing the location of the ship whenever he wants, as long as the ship remains horizontal and completely on the board, and the new location is consistent with all the information he has given so far. For example, for a 1x4 board and 1x2 ship, your little brother could initially place the ship such that it overlaps the leftmost two columns. If your first guess was row 1, column 2, he could choose to secretly move the ship to the rightmost two columns, and tell you that (1, 2) was a miss. If your next guess after that was (1, 3), though, then he could not say that was also a miss and move the ship back to its original location, since that would be inconsistent with what he said about (1, 2) earlier.

Not only do you know that your little brother will cheat, he knows that you know. If you both play optimally (you to minimize your score, him to maximize it), what is the lowest score that you can guarantee you will achieve, regardless of what your little brother does?

์ž…๋ ฅ

The first line of the input gives the number of test cases, T. T lines follow, each with three space-separated integers R, C, and W: the number of rows and columns of the board, followed by the width of the ship.

Limits

  • 1 โ‰ค W โ‰ค C.
  • T = 55.
  • R = 1.
  • 1 โ‰ค C โ‰ค 10.

์ถœ๋ ฅ

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the minimum score you can guarantee.

๐Ÿš€ํ’€์ด

  • ๋ฌธ์ œ ์ •๋ฆฌ
    • ๋ณด๋“œ๋Š” R x C ํฌ๊ธฐ์˜ ์ง์‚ฌ๊ฐํ˜•์ž…๋‹ˆ๋‹ค.
    • ๋ฐฐ๋Š” 1 x W ํฌ๊ธฐ์˜ ์ˆ˜ํ‰ ๋ฐฐ๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.
    • ๊ฒŒ์ž„์€ ์—ฌ๋Ÿฌ ๋ผ์šด๋“œ๋กœ ์ง„ํ–‰๋˜๋ฉฐ, ๊ฐ ๋ผ์šด๋“œ๋งˆ๋‹ค ์ฃผ์–ด์ง„ ์œ„์น˜๊ฐ€ ๋ฐฐ์˜ ์ผ๋ถ€์ธ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
    • ๋ฐฐ๋Š” ์ ˆ๋Œ€ ํšŒ์ „ํ•  ์ˆ˜ ์—†์œผ๋ฉฐ, ๋ฐฐ์น˜๊ฐ€ ๋™์ƒ์˜ ์ž„์˜์ ์ธ ์œ„์น˜ ๋ณ€๊ฒฝ์œผ๋กœ ์ธํ•ด ์ตœ์ ์˜ ๊ฒฝ์šฐ๋กœ ์˜ฎ๊ฒจ์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    • ๋ชฉํ‘œ๋Š” ์ตœ์†Œํ•œ์˜ ๋ผ์šด๋“œ ์ˆ˜๋กœ ๋ฐฐ์˜ ์œ„์น˜๋ฅผ ์ •ํ™•ํžˆ ์ฐพ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.
  • ํ•ด๊ฒฐ ์ „๋žต
    • ๊ธฐ๋ณธ ๊ฐœ๋…: Rํ–‰ C์—ด์˜ ๋ณด๋“œ์—์„œ, ๋ฐฐ์˜ ๊ธธ์ด W๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ ์ตœ์•…์˜ ๊ฒฝ์šฐ๋ฅผ ๊ณ ๋ คํ•˜์—ฌ ์ตœ์†Œ ์ถ”์ธก ํšŸ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.
  • ์ตœ์ ์˜ ์ „๋žต:
    • ๊ฐ ํ–‰์„ ๋…๋ฆฝ์ ์œผ๋กœ ์ƒ๊ฐํ•˜์—ฌ ๊ฐ ํ–‰๋งˆ๋‹ค ์ตœ์†Œํ•œ์˜ ์‹œ๋„๋กœ ๋ฐฐ๋ฅผ ์ฐพ์Šต๋‹ˆ๋‹ค.
    • ๊ฐ ํ–‰์—์„œ์˜ ์ตœ์†Œ ์‹œ๋„ ํšŸ์ˆ˜๋Š” C // W์ž…๋‹ˆ๋‹ค. ์ด ๊ฐ’์€ ๊ฐ ํ–‰์—์„œ W ๊ธธ์ด์˜ ๋ฐฐ๋ฅผ ์ฐพ๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ์ตœ์†Œํ•œ์˜ ์‹œ๋„์ž…๋‹ˆ๋‹ค.
    • ๋ฐฐ๊ฐ€ ํฌํ•จ๋œ ๋งˆ์ง€๋ง‰ ์œ„์น˜๋ฅผ ์ฐพ๊ธฐ ์œ„ํ•ด ์ถ”๊ฐ€์ ์ธ W-1 ์‹œ๋„๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
    • ์—ฌ๋Ÿฌ ํ–‰์„ ๊ณ ๋ คํ•˜์—ฌ ์ตœ์ข… ์ ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.

์„ค๋ช…

  1. ๊ธฐ๋ณธ ์‹œ๋„ ํšŸ์ˆ˜: ๊ฐ ํ–‰์—์„œ C / W๋งŒํผ์˜ ์‹œ๋„ ํšŸ์ˆ˜๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ๊ฐ ํ–‰์—์„œ ๋ฐฐ์˜ ์œ„์น˜๋ฅผ ์ฐพ๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ์ตœ์†Œ ์‹œ๋„ ํšŸ์ˆ˜์ž…๋‹ˆ๋‹ค.
  2. ์ถ”๊ฐ€ ์‹œ๋„ ํšŸ์ˆ˜: ๋ฐฐ์˜ ์ •ํ™•ํ•œ ์œ„์น˜๋ฅผ ์ฐพ๊ธฐ ์œ„ํ•ด ๋งˆ์ง€๋ง‰์œผ๋กœ W - 1๋ฒˆ์˜ ์ถ”๊ฐ€ ์‹œ๋„๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
  3. ์ตœ์ข… ์‹œ๋„ ํšŸ์ˆ˜: ๋ชจ๋“  ํ–‰์— ๋Œ€ํ•ด ๊ธฐ๋ณธ ์‹œ๋„ ํšŸ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•œ ํ›„, ์ถ”๊ฐ€ ์‹œ๋„ ํšŸ์ˆ˜๋ฅผ ๋”ํ•˜์—ฌ ์ตœ์ข… ์‹œ๋„ ํšŸ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.
  4. ์ถ”๊ฐ€ ์ ๊ฒ€: C % W != 0์ผ ๊ฒฝ์šฐ ํ•œ ๋ฒˆ ๋” ์‹œ๋„ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
void solve()
{
    int T;
    cin >> T;

    for (int t = 1; t <= T; ++t) 
    {
        int R, C, W;
        cin >> R >> C >> W;

        // ๊ฐ ํ–‰๋งˆ๋‹ค W ๊ธธ์ด์˜ ๋ฐฐ๋ฅผ ์ฐพ๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ์ตœ์†Œ ์‹œ๋„ ํšŸ์ˆ˜
        int moves_per_row = C / W;

        // ๋งˆ์ง€๋ง‰ ๋ถ€๋ถ„์—์„œ ๋ฐฐ์˜ ์œ„์น˜๋ฅผ ์ •ํ™•ํžˆ ์ฐพ๊ธฐ ์œ„ํ•ด W-1๋ฒˆ์˜ ์ถ”๊ฐ€ ์‹œ๋„๊ฐ€ ํ•„์š”
        int additional_moves = W - 1;

        // ๋ชจ๋“  ํ–‰์—์„œ ๊ธฐ๋ณธ์ ์ธ ์‹œ๋„ ํšŸ์ˆ˜๋ฅผ ๊ณ„์‚ฐ
        int total_moves = moves_per_row * R + additional_moves;

        // ๋ฐฐ๊ฐ€ ์ •ํ™•ํžˆ C์™€ ์ผ์น˜ํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ๋ฅผ ์œ„ํ•ด ์ถ”๊ฐ€ ์ ๊ฒ€
        if (C % W != 0) 
        {
            total_moves += 1;
        }

        cout << "Case #" << t << ": " << total_moves << '\n';
    }
}

๐Ÿš€์ฝ”๋“œ

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include<iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>

using namespace std;

void solve()
{
    int T;
    cin >> T;

    for (int t = 1; t <= T; ++t) 
    {
        int R, C, W;
        cin >> R >> C >> W;

        // ๊ฐ ํ–‰๋งˆ๋‹ค W ๊ธธ์ด์˜ ๋ฐฐ๋ฅผ ์ฐพ๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ์ตœ์†Œ ์‹œ๋„ ํšŸ์ˆ˜
        int moves_per_row = C / W;

        // ๋งˆ์ง€๋ง‰ ๋ถ€๋ถ„์—์„œ ๋ฐฐ์˜ ์œ„์น˜๋ฅผ ์ •ํ™•ํžˆ ์ฐพ๊ธฐ ์œ„ํ•ด W-1๋ฒˆ์˜ ์ถ”๊ฐ€ ์‹œ๋„๊ฐ€ ํ•„์š”
        int additional_moves = W - 1;

        // ๋ชจ๋“  ํ–‰์—์„œ ๊ธฐ๋ณธ์ ์ธ ์‹œ๋„ ํšŸ์ˆ˜๋ฅผ ๊ณ„์‚ฐ
        int total_moves = moves_per_row * R + additional_moves;

        // ๋ฐฐ๊ฐ€ ์ •ํ™•ํžˆ C์™€ ์ผ์น˜ํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ๋ฅผ ์œ„ํ•ด ์ถ”๊ฐ€ ์ ๊ฒ€
        if (C % W != 0) 
        {
            total_moves += 1;
        }

        cout << "Case #" << t << ": " << total_moves << '\n';
    }
}

int main()
{
	FILE* stream;
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	freopen_s(&stream, "input.txt", "rt", stdin);

	solve();

	return 0;
}

ํƒœ๊ทธ:

์นดํ…Œ๊ณ ๋ฆฌ:

์—…๋ฐ์ดํŠธ: