本文已参与「新人创作礼」活动,一起开启掘金创作之路。
@TOC
Технокубок 2021 - Финал-A. Prison Break
传送门 Time Limit: 1 second Memory Limit: 256 megabytes
Problem Description
Michael is accused of violating the social distancing rules and creating a risk of spreading coronavirus. He is now sent to prison. Luckily, Michael knows exactly what the prison looks like from the inside, especially since it's very simple.
The prison can be represented as a rectangle which is divided into cells, each representing a prison cell, common sides being the walls between cells, and sides on the perimeter being the walls leading to freedom. Before sentencing, Michael can ask his friends among the prison employees to make (very well hidden) holes in some of the walls (including walls between cells and the outermost walls). Michael wants to be able to get out of the prison after this, no matter which cell he is placed in. However, he also wants to break as few walls as possible.
Your task is to find out the smallest number of walls to be broken so that there is a path to the outside from every cell after this.
Input
The first line contains a single integer () — the number of test cases.
Each of the following lines contains two integers and (), representing a corresponding test case.
Output
For each test case print the single integer on a separate line — the answer to the problem.
Sample Input
2
2 2
1 3
Sample Onput
4
3
Note
Some possible escape plans for the example test cases are shown below. Broken walls are shown in gray, not broken walls are shown in black.
题目大意
有囚犯因违背疫情防控被抓,他买通了狱友,让狱友给墙上打洞,使得他不论在哪个房间都能出去。 问最少需要破坏多少的墙。
配图方格是房间,直线是墙。黑色的线是没有破坏的墙,灰色的线是被破坏的墙。
解题思路
要想出去,首先必须要有一个与外界相邻的墙被打通。打通了这堵墙就又一个房间通向外界了。 之后,要想在其他每个房间都有出去的路,则每个房间都最少破坏一堵墙,来
- 直接与外界相通 或
- 与已经与外界相通的房间相通
总之,有几个房间就需要破坏几堵墙。 题目不难,主要是得读懂题意。
AC代码
#include <iostream>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define fi(i, l, r) for (int i = l; i < r; i++)
#define cd(a) scanf("%d", &a)
typedef long long ll;
int main()
{
int N;
cin >> N;
while (N--)
{
int a, b;
cin >> a >> b;
cout << a * b << endl;
}
return 0;
}
同步发文于我的CSDN,原创不易,转载请附上原文链接哦~ Tisfy:blog.csdn.net/Tisfy/artic…
至于为什么赛后比赛不可见并且变成了我也不清楚