AtCoder Beginner Contest 218 A~D

比赛链接:Here

A - Weather Forecas

水题,判断 s[n1]=o 的话输出 YES

B - qwerty

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

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

C - Shapes

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

数据范围:1N200

思路:

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

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

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

那枚举每个 SvectorTvector 每个点的 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\n"; return ;}
    if (v1.size() == 0 and v2.size() == 0) {cout << "Yes\n"; 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\n" : "No\n");
}

D - Rectangles

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

数据范围:0xi,yi1e9,(xi,yi)(xj,yj)(ij)

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

这样一来,一个矩形会被计算两次(两条对角线),所以答案要除以 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 << "\n";
}

EFG待补

posted @   RioTian  阅读(68)  评论(0编辑  收藏  举报
编辑推荐:
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
阅读排行:
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· 分享4款.NET开源、免费、实用的商城系统
· 解决跨域问题的这6种方案,真香!
· 一套基于 Material Design 规范实现的 Blazor 和 Razor 通用组件库
· 5. Nginx 负载均衡配置案例(附有详细截图说明++)
历史上的今天:
2020-09-12 Problem B - Card Constructions (构造)
2020-09-12 Problem A - Sequence with Digits (数学推导)
点击右上角即可分享
微信分享提示

📖目录