首页 > 其他分享 >The 2nd Universal Cup. Stage 2: SPb

The 2nd Universal Cup. Stage 2: SPb

时间:2023-09-16 21:55:42浏览次数:50  
标签:Cup int Universal cin ++ abs ans using SPb

链接:https://contest.ucup.ac/contest/1356

A. Mixed Messages

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    string s;
    cin >> n >> s;

    vector<int> a(n, -1), b(n, -1);
    vector<int> p(4, -1);
    for (int i = 0; i < n; i++) {
        if (s[i] == 's') {
            p[0] = i;
        }
        if (s[i] == 'p') {
            p[1] = i;
            a[i] = p[0];
        }
        if (s[i] == 'b') {
            p[2] = i;
            a[i] = p[1];
        }
        if (s[i] == 'u') {
            p[3] = i;
        }
    }
    p.assign(4, -1);
    for (int i = n - 1; i >= 0; i--) {
        if (s[i] == 's') {
            p[0] = i;
            b[i] = p[3];
        }
        if (s[i] == 'p') {
            p[1] = i;
        }
        if (s[i] == 'b') {
            p[2] = i;
            b[i] = p[0];
        }
        if (s[i] == 'u') {
            p[3] = i;
        }
    }

    int ans = 1E9;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'b') {
            int a2 = i;
            int a1 = a[a2];
            int a3 = b[a2];
            if (a1 != -1 && a3 != -1) {
                int a0 = a[a1];
                int a4 = b[a3];
                if (a0 != -1 && a4 != -1) {
                    ans = min(ans, abs(a0 - a2 + 2) + abs(a1 - a2 + 1) + abs(a3 - a2 - 1) + abs(a4 - a2 - 2));
                }
            }
        }
    }
    cout << ans << '\n';

    return 0;
}

B. I Flipped The Calendar...

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    vector<int> ans(2038);
    int d[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int cur = 2;
    for (int i = 1970; i < 2038; i++) {
        if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)) {
            d[1] = 29;
        } else {
            d[1] = 28;
        }
        for (int j = 0; j < 12; j++) {
            ans[i]++;
            for (int k = 0; k < d[j]; k++) {
                cur++;
                if (cur == 7) {
                    if (k != 0) {
                        ans[i]++;
                    }
                    cur = 0;
                }
            }
        }
    }
    
    int y;
    cin >> y;
    cout << ans[y] << '\n';

    return 0;
}

D. Bishops

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, m;
    cin >> n >> m;

    vector<pair<int, int>> ans;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> q[2];

    vector<vector<pair<int, int>>> a(n + m - 1);
    for (int i = -m + 1; i < n; i++) {
        int l = max(-i, i);
        int r = min(2 * n - 2 - i, 2 * m - 2 + i);
        a[l].push_back({r, i});
    }

    for (int j = 0; j < n + m - 1; j++) {
        int d = j % 2;
        for (auto &x : a[j]) {
            q[d].push(x);
        }
        while (!q[d].empty() && q[d].top().second < j) {
            q[d].pop();
        }
        if (!q[d].empty()) {
            auto [r, i] = q[d].top();
            q[d].pop();   
            ans.push_back({(i + j) / 2, (j - i) / 2});         
        }
    }

    cout << ans.size() << '\n';
    for (auto &[x, y] : ans) {
        cout << x + 1 << ' ' << y + 1 << '\n';
    }

    return 0;
}

I. Password

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    if (n % 2 == 1) {
        cout << 1 + (n / 2 / 3) * 2;
    } else {
        cout << 2 + ((n - 2) / 2 / 3) * 2;
    }
    cout << ' ' << n << '\n';

    return 0;
}

J. Transport Pluses

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

using Point = complex<double>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, t;
    cin >> n >> t;
    int x, y;
    cin >> x >> y;
    Point s(x, y);
    cin >> x >> y;
    Point e(x, y);
    vector<Point> a(n);
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        a[i] = Point(x, y);
    }

    vector<vector<int>> b;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            b.push_back({i, j});
        }
    }
    b.push_back({});

    double ans = 1E18;
    for (int i = 0; i < (int) b.size(); i++) {
        double res = 0;
        if ((int) b[i].size() == 0) {
            res += abs(s - e);
        } else {
            auto a0 = a[b[i][0]];
            auto a1 = a[b[i][1]];

            if (abs(real(s) - real(a0)) < abs(imag(s) - imag(a0))) {
                res += abs(real(s) - real(a0));
            } else {
                res += abs(imag(s) - imag(a0));
            }
            res += t;
            if (b[i][0] != b[i][1]) {
                res += t;
            }
            if (abs(real(e) - real(a1)) < abs(imag(e) - imag(a1))) {
                res += abs(real(e) - real(a1));
            } else {
                res += abs(imag(e) - imag(a1));
            }
        }
        ans = min(ans, res);
    }

    cout << fixed << setprecision(9) << ans << '\n';
    for (int i = 0; i < (int) b.size(); i++) {
        double res = 0;
        if ((int) b[i].size() == 0) {
            res += abs(s - e);
        } else {
            auto a0 = a[b[i][0]];
            auto a1 = a[b[i][1]];

            if (abs(real(s) - real(a0)) < abs(imag(s) - imag(a0))) {
                res += abs(real(s) - real(a0));
            } else {
                res += abs(imag(s) - imag(a0));
            }
            res += t;
            if (b[i][0] != b[i][1]) {
                res += t;
            }
            if (abs(real(e) - real(a1)) < abs(imag(e) - imag(a1))) {
                res += abs(real(e) - real(a1));
            } else {
                res += abs(imag(e) - imag(a1));
            }
        }

        if (abs(res - ans) <= 1E-9) {
            if ((int) b[i].size() == 0) {
                cout << "1\n0 " << real(e) << ' ' << imag(e) << '\n';
            } else {
                auto a0 = a[b[i][0]];
                auto a1 = a[b[i][1]];
                cout << 3 + (b[i][0] != b[i][1]) << '\n';
                if (abs(real(s) - real(a0)) < abs(imag(s) - imag(a0))) {
                    cout << "0 " << real(a0) << ' ' << imag(s) << '\n';
                } else {
                    cout << "0 " << real(s) << ' ' << imag(a0) << '\n';
                }
                if (b[i][0] != b[i][1]) {
                    cout << b[i][0] + 1 << ' ' << real(a0) << ' ' << imag(a1) << '\n';
                }
                if (abs(real(e) - real(a1)) < abs(imag(e) - imag(a1))) {
                    cout << b[i][1] + 1 << ' ' << real(a1) << ' ' << imag(e) << '\n';
                } else {
                    cout << b[i][1] + 1 << ' ' << real(e) << ' ' << imag(a1) << '\n';
                }	
                cout << "0 " << real(e) << ' ' << imag(e) << '\n';
            }
            break;
        }
    }    

    return 0;
}

标签:Cup,int,Universal,cin,++,abs,ans,using,SPb
From: https://www.cnblogs.com/kiddingma/p/17707378.html

相关文章

  • armbian安装cups打印服务器
    一、安装cups服务1、apt-getinstallcupsavahi-daemon-y2、安装驱动HP驱动:apt-getinstallhplip-y爱普生驱动:apt-getinstallprinter-driver-gutenprint兄弟驱动:apt-getinstallprinter-driver-brlaser3、systemctlrestartcups二、修改配置文件1、找到:Listenlocalhos......
  • 洛谷 AT_maximum_cup_2018_a フィギュアスケート界の貴公子埼大選手 の 题解
    这道题是一道水题,所以你的代码很可能与我相似或相同,如果你的代码出现了问题,你很可能在我的题解里找出答案。这道题大概思路是一旦$10$秒后运动员会接触到毛绒玩具,那么就加上在这个点上毛绒玩具的数量。但是!这道题有一道巨坑的点!由于这道题比较远古,所以说你即使是正解,你也要在......
  • * Dytechlab Cup 2022 A. Ela Sorting Books
    \(n\)本书必须分成\(k\)部分在书架(\(k\midn\)),每本书用一个小写的拉丁字母\([a,y]\)表示。每部分必须有严格\(\frac{n}{k}\)本书。当所有书分配完成后,对于每个部分编号为\(1,2,\cdots,k\),每部分的有\(\frac{n}{k}\)本书,他们的\(MEX\)表示这个部分,作为代表字符......
  • The 2nd Universal Cup. Stage 1: Qingdao
    GDescription给定一个数列,每次ban一个位置,在每次ban之前,求连续子序列逆序对数的最大值,强制在线。(6s)\(n\leq10^5,\sumn\leq10^6\)Solution先考虑用权值线段树来维护区间逆序对数,不难支持在原数列前后加或删除一个数。然后考虑原题的分裂过程,将一段\([l,r]\)分裂成\([l,p-......
  • Java 服务器cup占用率过高 以及 内存泄漏排查方法
    cup占用率过高常见能够引起CPU100%异常的情况都有哪些?Java 内存不够或者溢出导致GCoverheadlimitexceeded。代码中互相竞争导致的死锁。特别耗费计算资源的操作,比如正则匹配,Java中的正则匹配默认有回溯问题,复杂的正则匹配引起的CPU异常。死循环引起的CPU高度密集计算。针对第1......
  • 如何使用MicroPython将Raspberry Pi Pico W与伺服电机连接?
    PicoW是一款经济实惠且紧凑的微控制器板,基于RP2040芯片,非常适合嵌入式系统和物联网项目。MicroPython是Python的轻量级实现,为微控制器编程提供了用户友好的环境。通过遵循概述的步骤,读者将学习如何将伺服电机连接到PicoW、编写MicroPython代码来控制其运动,并获得将精确......
  • Raspberry Pi 内网穿透实战教程 All In One
    RaspberryPi内网穿透实战教程AllInOne树莓派使用场景使用RaspberryPi搭建个人Web项目的服务器,并且提供外网访问的能力(Web,SSH)数据安全,私有代码低成本服务器容器化微服务全栈开发demos(......
  • 树莓派Raspbian安装PYQT5
     安装PYQT5.(树莓派Raspbian下pip3installPyQt5是无法正常安装的。)https://zhuanlan.zhihu.com/p/498682983 准备工作。pipinstallwheelsudoapt-getupdate Pip3installsip可直接用官方仓库安装。 sudoaptinstall-ypython3-pyqt5额外组件sudoaptin......
  • Raspberry Pi OS 开启 root 用户并设置为默认自动登录
    1、设置密码#sudopasswdroot2、启用root 用户#sudopassd--unlockroot3、开启root 用户ssh登录的权限。修改/etc/ssh/sshd_config文件,新增一行  PermitRootLoginyes,(此步骤可忽略)PermitRootLoginyesUsePAMyes4、修改 /etc/systemd/system/autolo......
  • 机器人编程教程3探索Raspberry Pi
    3探索RaspberryPi本章将涉及以下主题:探索RaspberryPi的功能选择连接什么是RaspberryPiOS?为RaspberryPiOS准备SD卡3.1探索RaspberryPi的功能控制器将决定机器人的输入和输出类型、电子设备的功率要求、可使用的传感器类型以及运行的代码。更改控制器可能意......