加载中...

AtCoder题解|Ruined Square


本篇博客还在持续修改润色中~

敬请期待~

AtCoder题解|ABC 108B Ruined Square


题目信息 📚

【题目描述】

There is a square in the xy-plane. The coordinates of its four vertices are $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$, and $(x_4, y_4)$ in counter-clockwise order. (Assume that the positive x-axis points right, and the positive y-axis points up.)

Takahashi remembers $(x_1, y_1)$ and $(x_2, y_2)$, but he has forgotten $(x_3, y_3)$ and $(x_4, y_4)$.

Given $x_1$, $x_2$, $y_1$, $y_2$, restore $x_3$, $y_3$, $x_4$, $y_4$. It can be shown that $x_3$, $y_3$, $x_4$, and $y_4$ uniquely exist and have integer values.

【输入】

The input is given from Standard Input in the following format:

$x_1$ $y_1$ $x_2$ $y_2$

【输出】

Print $x_3$, $y_3$, $x_4$, $y_4$ as integers, in this order.

【数据范围】

  • $|x_1|$, $|y_1|$, $|x_2|$, $|y_2| \leq 100$
  • $(x_1, y_1) \neq (x_2, y_2)$
  • All values in the input are integers.

【输入样例1】

0 0 0 1

【输出样例1】

-1 1 -1 0

For example, $(0,0)$, $(0,1)$, $(-1,1)$, $(-1,0)$ are the four vertices of a square in counter-clockwise order. Note that $(x_3, y_3) = (1,1)$, $(x_4, y_4) = (1,0)$ is not accepted, as the vertices are in clockwise order.

【输入样例2】

2 3 6 6

【输出样例2】

3 10 -1 7

【输入样例3】

31 -41 -59 26

【输出样例3】

-126 -64 -36 -131

【题目来源】

https://atcoder.jp/contests/abc107/tasks/abc107_b


题目解析 🍉

【题目分析】

模拟 + 打标记即可。

【C++代码】

#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
const int N = 110;
string g[N];
bool row[N], col[N];
int h, w;

int main() {
    ios::sync_with_stdio(false);  //cin读入优化
    cin.tie(0);

    // 读入数据
    cin >> h >> w;
    for (int i = 0; i < h; i++) cin >> g[i];
    // 行判断
    for (int i = 0; i < h; i++) {
        row[i] = true;
        for (int j = 0; j < w; j++) {
            if (g[i][j] == '#') {
                row[i] = false;
                break;
            }
        }
    }
    // 列判断
    for (int i = 0; i < w; i++) {
        col[i] = true;
        for (int j = 0; j < h; j++) {
            if (g[j][i] == '#') {
                col[i] = false;
                break;
            }
        }
    }
    // 根据判断数组输出答案
    for (int i = 0; i < h; i++) {
        if (row[i]) continue;
        else {
            for (int j = 0; j < w; j++) {
                if (!col[j]) cout << g[i][j];
            }
            cout << endl;
        }
    }

    return 0;
}

文章作者: Rickyの水果摊
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Rickyの水果摊 !
  目录