洛谷 AT_abc269_b [ABC269B]:Rectangle Detection

【题目来源】
https://www.luogu.com.cn/problem/AT_abc269_b
https://atcoder.jp/contests/abc269/tasks/abc269_b

【题目描述】
Takahashi generated 10 strings S1, S2, ..., S10 as follows.
• First, let Si(1≤i≤10)=..........(10 .s in a row).
• Next, choose four integers A, B, C, and D satisfying all of the following.
○ 1≤A≤B≤10.
○ 1≤C≤D≤10.
• Then, for every pair of integers (i,j) satisfying all of the following, replace the j-th character of Si with #.
○ A≤i≤B.
○ C≤j≤D.
You are given S1, S2, ....., S10 generated as above. Find the integers A, B, C, and D Takahashi chose.
It can be proved that such integers A, B, C, and D uniquely exist (there is just one answer) under the Constraints.

塔哈夫什按照以下方式生成了 10 个字符串 S1、S2、......、S10。
• 首先,令 Si(1≤i≤10)= ......(连续 10 个字符 ".")。
• 接下来,选择四个整数 A、B、C 和 D,满足以下所有条件。
○ 1≤A≤B≤10。
○ 1≤C≤D≤10。
• 然后,对于满足以下所有条件的每一个整数对 (i,j) ,将 Si 的第 j 个字符替换为 #。
○ A≤i≤B。
○ C≤j≤D。
现在给定按照上述方法生成的 S1,S2,...,S10,请你求出高桥君选择的整数 A,B,C,D。根据题目限制,可以证明 A,B,C,D 的值是唯一确定的(即答案唯一)。

【输入格式】
The input is given from Standard Input in the following format:
S1
S2
...
S10

输入将以以下格式从标准输入中给出:
S1
S2
...
S10

【输出格式】
Print the answer in the following format:
A B
C D

请按照以下格式输出答案:
A B
C D

【输入样例一】

cpp 复制代码
..........
..........
..........
..........
...######.
...######.
...######.
...######.
..........
..........

【输出样例一】

cpp 复制代码
5 8
4 9

【输入样例二】

cpp 复制代码
..........
..#.......
..........
..........
..........
..........
..........
..........
..........
..........

【输出样例二】

cpp 复制代码
2 2
3 3

【输入样例三】

cpp 复制代码
##########
##########
##########
##########
##########
##########
##########
##########
##########
##########

【输出样例三】

cpp 复制代码
1 10
1 10

【数据范围】
S1, S2, ..., S10 are strings, each of length 10, that can be generated according to the Problem Statement.
S1、S2、...、S10 均为字符串,每个字符串的长度均为 10,它们可依据问题说明进行生成。

【算法分析】
● 样例一的解释:
在这里,塔哈夫什选择了 ++A = 5、B = 8、C = 4、D = 9++ 。
这一选择生成了 10 个长度为 10 的字符串 S1、S2、......、S10,其中 ++S5、S6、S7、S8 的第 4 个到第 9 个字符是"#",其余字符则是"."++ 。
这些字符串与输入中给出的字符串完全相同。

● vector<string> s(N); 的作用是创建一个名为 s 的、存储 string(字符串)类型元素的动态数组,并且初始化这个数组的大小为 N,每个元素都是空字符串 ""。

【算法代码】

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

const int N=12;
vector<string> s(N);
int a=INT_MAX,b=INT_MIN;
int c=INT_MAX,d=INT_MIN;

int main() {
    for(int i=0; i<10; i++) cin>>s[i];

    for(int i=0; i<10; i++) {
        for(int j=0; j<10; j++) {
            if(s[i][j]=='#') {
                a=min(a,i),b=max(b,i);
                c=min(c,j),d=max(d,j);
            }
        }
    }
    cout<<a+1<<" "<<b+1<<endl;
    cout<<c+1<<" "<<d+1<<endl;
}

/*
in:
..........
..........
..........
..........
...######.
...######.
...######.
...######.
..........
..........

out:
5 8
4 9
*/

【参考文献】
https://www.luogu.com.cn/problem/solution/AT_abc269_b
https://blog.csdn.net/weixin_73010943/article/details/137162831

相关推荐
Tisfy17 天前
LeetCode 3838.带权单词映射:求和、取模、拼接(附python一行版)
python·算法·leetcode·字符串·题解·模拟·取模
阿方.9181 个月前
C++ string 超全精讲 | 从零使用、底层原理、手搓简易string、高频考点、易错点、面试手撕
开发语言·c++·字符串·string·知识分享
罗湖老棍子1 个月前
The xor-longest Path(信息学奥赛一本通- P1478)
算法·字符串·字典树··lca最近公共祖先
金创想1 个月前
积木移动题目分析及解题思路——木块问题(1)
c++·算法·字符串·c·刷题·信息学奥赛·积木
进击的荆棘1 个月前
优选算法——字符串
开发语言·c++·算法·leetcode·字符串
王老师青少年编程1 个月前
csp信奥赛C++高频考点专项训练之字符串 --【字符串综合】:[NOIP 2015 提高组] 子串
c++·字符串·csp·高频考点·子串·信奥赛
王老师青少年编程1 个月前
csp信奥赛C++高频考点专项训练之字符串 --【字符串综合】:遍历问题
c++·字符串·csp·高频考点·信奥赛
你很易烊千玺1 个月前
日常练习-数组 字符串常用的场景
前端·javascript·字符串·数组
王老师青少年编程2 个月前
csp信奥赛C++高频考点专项训练之字符串 --【字符串排序】:字符排序
c++·字符串·csp·高频考点·信奥赛·字符串排序·字符排序
王老师青少年编程2 个月前
csp信奥赛C++高频考点专项训练之字符串 --【字符串综合】:[NOIP 2004 普及组] FBI 树
c++·字符串·csp·高频考点·信奥赛·字符串综合·fbi树