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

The 2nd Universal Cup. Stage 2- SPb

时间:2023-09-25 20:34:58浏览次数:40  
标签:Cup int Universal ye back xe abs path SPb

A. Mixed Messages

dp[i][j]表示前i位,选择\(j\)个移动到一起的最小花费。

#include<bits/stdc++.h>

using namespace std;

#define int long long
constexpr int inf = 1E9;


int32_t main() {
    int n;
    string s;
    cin >> n >> s;
    const string t = "spbsu";
    array<int, 6> dp;
    dp.fill(inf), dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 4; j >= 0; j--)
            if (t[j] == s[i])
                dp[j + 1] = min(dp[j + 1], dp[j] + (j < 2 ? -1 : j > 2 ? 1 : 0) * i);
    }
    cout << dp[5] - 6 << "\n";
    return 0;
}

B. I Flipped The Calendar...

直接模拟这个过程

#include <bits/stdc++.h>

using namespace std;

set<int> s;
int m[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

// 1791 61

int32_t main() {
    for (int i = 2000; i <= 2037; i += 4) s.insert(i);
    for (int i = 2000; i >= 1970; i -= 4) s.insert(i);
    int Y = 1970, Date = 3;
    int y;
    cin >> y;
    for (int i = 1970; i < y; i++) {
        Date = (Date + 365 + s.count(i)) % 7;
    }
    int res = 0;
    for (int i = 1, M, ans; i <= 12; i++) {
        M = m[i];
        if (i == 2) M += s.count(y);

        ans = 1, Date = (Date + 1) % 7;
        for (int j = 2; j <= M; j++, Date = (Date + 1) % 7) {
            if( Date == 6 ) cout << "\n";
            if (Date == 0) ans++;

        }
        res += ans;
    }
    cout << res << "\n";
    return 0;
}

I. Password

#include <bits/stdc++.h>

using namespace std;

#define int long long


int32_t main() {
    int n;
    cin >> n;
    if (n & 1) {
        int m = (n + 1) / 2;
        cout << (m + 2) / 3 * 2 - 1;
    } else {
        int m = n / 2;
        cout << (m + 2) / 3 * 2;
    }
    cout << " " << n << "\n";
    return 0;
}

J. Transport Pluses

可以注意到的是,任意两个加号是一定相交的,所以最多只用经过两个加号,这样的话我们只需要枚举中间经过那些加号即可。

#include<bits/stdc++.h>

using namespace std;

//#define int long long

constexpr int inf = 1E9;

using vi = vector<int>;


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

    int n, t;
    cin >> n >> t;

    int xh, yh;
    cin >> xh >> yh;

    int xe, ye;
    cin >> xe >> ye;

    vi x(n), y(n);

    for (int i = 0; i < n; i++)
        cin >> x[i] >> y[i];

    double ans = sqrt((xh - xe) * (xh - xe) + (yh - ye) * (yh - ye));
    vector<array<int, 3>> path;
    path.push_back({0, xe, ye});

    for (int i = 0, cost; i < n; i++)
        for (int j = 0; j < n; j++) {
            if (i == j) {
                cost = min(abs(xh - x[i]), abs(yh - y[i])) + t + min(abs(xe - x[i]), abs(ye - y[i]));
                if (cost >= ans) continue;

                ans = cost, path.clear();
                if (abs(xh - x[i]) < abs(yh - y[i]))
                    path.push_back({0, x[i], yh});
                else
                    path.push_back({0, xh, y[i]});
                if (abs(xe - x[i]) < abs(ye - y[i]))
                    path.push_back({i + 1, x[i], ye});
                else
                    path.push_back({i + 1, xe, y[i]});
                path.push_back({0, xe, ye});
            } else {
                cost = min(abs(xh - x[i]), abs(yh - y[i])) + t + t + min(abs(xe - x[j]), abs(ye - y[j]));
                if (cost >= ans) continue;
                ans = cost, path.clear();
                if (abs(xh - x[i]) < abs(yh - y[i]))
                    path.push_back({0, x[i], yh});
                else
                    path.push_back({0, xh, y[i]});
                path.push_back({i + 1, x[i], y[j]});
                if (abs(xe - x[j]) < abs(ye - y[j]))
                    path.push_back({j + 1, x[j], ye});
                else
                    path.push_back({j + 1, xe, y[j]});
                path.push_back({0, xe, ye});
            }
        }
    cout << fixed << setprecision(10) << ans << "\n" << path.size() << "\n";
    for (auto [a, b, c]: path)
        cout << a << " " << b << " " << c << "\n";
    return 0;
}

标签:Cup,int,Universal,ye,back,xe,abs,path,SPb
From: https://www.cnblogs.com/PHarr/p/17728784.html

相关文章

  • Ubuntu 23.10/24.04 LTS 放弃默认使用 snap 版 CUPS 打印堆栈
    导读Canonical的开发者、OpenPrinting的项目负责人TillKamppeter今年5月表示,计划在Ubuntu23.10(ManticMinotaur)上默认使用Snap版本的CUPS打印堆栈。不过经过数月的测试,官方放弃了这项决定。Ubuntu23.10(ManticMinotaur)和Ubuntu24.04LTS发行版默认还是......
  • The 2nd Universal Cup. Stage 2: SPb
    链接:https://contest.ucup.ac/contest/1356A.MixedMessages#include"bits/stdc++.h"usingnamespacestd;usingi64=longlong;intmain(){ios::sync_with_stdio(false);cin.tie(nullptr);intn;strings;cin>>n......
  • 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......