AtCoder Beginner Contest 218 A~D

比赛链接:Here

A - Weather Forecas

水题,判断 (s[n - 1] = o) 的话输出 YES

B - qwerty

题意:给出 ((1,2,...,26)) 的某个全排列 (p) ,请对于 (1le i le 26) 的每个 (p_i) ,输出第 (p_i) 个小写字母

void solve() {
    int n = 26;
    for (int i = 0, x; i < n; ++i) {
        cin >> x;
        cout << char('a' + x - 1);
    }
}

C - Shapes

题意:(n imes n) 的二维空间中有 (S,T) 两个图形,问能否经过任意次旋转 (90°) 和平移操作,使两图形相等?

数据范围:(1le Nle 200)

思路:

可以把 (S)​​ 和三种旋转出来的图形的 (#)​​ 的坐标分别存在 (4)​​ 个 (vector)​ 里 然后 (x)​ 优先 (y)​ 次优先排个序

然后把 (T)​ 的所有 (#)​ 的坐标也放到 (vector)​ 里排序

因为要是 yes 的话 (T)​ 肯定是 (S)​ 的 (4)​ 个 (vector) 中的其中一个 (vector) 平移出来的

那枚举每个 (S)(vector)(T)(vector) 每个点的 (x) 都相减 如果得出来的值都一样

再把 (y) 也做同样操作 如果也相同 那么就是平移出来的就是 yes ,如果旋转出来的所有情况都无法平移到 (T) 就输出No

struct node {int x, y;};
vector<node>v1, v2, v3, v4, v5;
bool cmp(node a, node b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }
bool check(vector<node> a, vector<node>b) {
    int n = a.size();
    int lx = a[0].x - b[0].x;
    int ly = a[0].y - b[0].y;
    for (int i = 0; i < n; i++) {
        if (a[i].x - b[i].x != lx) return false;
        if (a[i].y - b[i].y != ly) return false;
    }
    return true;
}
void solve() {
    int n; cin >> n;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j) {
            char c; cin >> c;
            if (c == '#') {
                v1.push_back({i, j});
                v2.push_back({j, n - i + 1});
                v3.push_back({n - j + 1, i});
                v5.push_back({n - i + 1, n - j + 1});
            }
        }
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j) {
            char c; cin >> c;
            if (c == '#')
                v4.push_back({i, j});
        }
    if (v1.size() != v4.size()) {cout << "No
"; return ;}
    if (v1.size() == 0 and v2.size() == 0) {cout << "Yes
"; return ;}
    sort(v1.begin(), v1.end(), cmp);
    sort(v2.begin(), v2.end(), cmp);
    sort(v3.begin(), v3.end(), cmp);
    sort(v4.begin(), v4.end(), cmp);
    sort(v5.begin(), v5.end(), cmp);
    int f = 0;
    if (check(v1, v4)) f = 1;
    if (check(v2, v4)) f = 1;
    if (check(v3, v4)) f = 1;
    if (check(v5, v4)) f = 1;
    cout << (f ? "Yes
" : "No
");
}

D - Rectangles

题意:已知二维平面上 (nle 2000) 个点,求能构成边平行于坐标轴的矩形的个数。

数据范围:(0le x_i,y_ile 1e9,(x_i,y_i) ot=(x_j,y_j)(i ot=j))

思路:枚举两个点作为矩形的对角线,并检查另外两个点是否也在平面上。

这样一来,一个矩形会被计算两次(两条对角线),所以答案要除以 (2)

struct node {
    int x, y;
    bool operator <(const node &nd) const {
        if (x == nd.x) return y < nd.y;
        else return x < nd.x;
    }
};
void solve() {
    int n; cin >> n;
    int x[n + 1], y[n + 1];
    map<node, int>mp;
    for (int i = 1; i <= n; i++)
        cin >> x[i] >> y[i], mp[(node) {x[i], y[i]}] = 1; //记录节点
    ll cnt = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = i + 1; j <= n; ++j) {
            if (x[i] == x[j] || y[i] == y[j]) continue;
            if (mp[(node) {x[i], y[j]}] == 1 and  mp[(node) {x[j], y[i]}] == 1) cnt += 1;
        }
    cout << cnt / 2 << "
";
}

EFG待补

The desire of his soul is the prophecy of his fate
你灵魂的欲望,是你命运的先知。

原文地址:https://www.cnblogs.com/RioTian/p/15257455.html