首页 > 编程语言 >2021年中国大学生程序设计竞赛女生专场

2021年中国大学生程序设计竞赛女生专场

时间:2023-07-23 15:22:04浏览次数:58  
标签:专场 int cin long i64 ++ 2021 using 程序设计

链接:https://codeforces.com/gym/103389

A. 公交线路

C++ Code
#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

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

    int n, x, y;
    cin >> n >> x >> y;

    x--, y--;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int m;
    cin >> m;
    vector<int> b(m);
    i64 t = 0;
    for (int i = 0; i < m; i++) {
        cin >> b[i];
        t *= 10;
        t += b[i];
    }
    if (x > y) {
        reverse(a.begin(), a.end());
        x = n - 1 - x;
        y = n - 1 - y;
    }
    i64 s1 = 0, s2 = 0;
    for (int i = x + 1; i < x + 1 + m; i++) {
        s1 *= 10;
        s1 += a[i];
    }
    for (int i = x - 1; i >= max(0, x - m); i--) {
        s2 *= 10;
        s2 += a[i];
    }
    if (s1 == t) {
        if (s2 == t) {
            cout << "Unsure\n";
        } else {
            cout << "Right\n";
        }
    } else {
        cout << "Wrong\n";
    }

    return 0;
}

D. 修建道路

C++ Code
#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;
    vector<int> a(n);
    i64 ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i < n; i++) {
        ans += max(a[i], a[i - 1]);
    }
    cout << ans << '\n';
    
    return 0;
}

F. 地图压缩

C++ Code
#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

constexpr int B = 114514;
constexpr i64 P = 1000000000039;

i64 *p;

void init(int N) {
    p = new i64 [N + 1];
    for (int i = 0; i <= N; i++) {
        p[i] = 0;
    } 
    p[0] = 1;
    for (int i = 1; i <= N; i++) {
        p[i] = p[i - 1] * B % P;
    }
}

struct StringHash {
    vector<i64> h;
    StringHash() : h(1) {}
    void push_back(char ch) {
        h.push_back((h.back() * B + ch) % P);
    }
    i64 get(int l, int r) { // [l, r)
        return (h[r] + __int128(h[l]) * (P - p[r - l])) % P;
    }
};

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

    int n, m;
    cin >> n >> m;
    vector<string> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector<vector<StringHash>> hs(2, vector<StringHash>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            hs[0][i].push_back(a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            hs[1][i].push_back(a[j][i]);
        }
    }

    auto getcir = [&](const vector<i64> &s) {
        int n = s.size();
        vector<int> nex(n + 1);
        int j = 0;
        for (int i = 1; i < n; i++) {
            while (j && s[i] != s[j]) {
                j = nex[j];
            }
            if (s[i] == s[j]) {
                j++;
            }
            nex[i + 1] = j;
        }
        return n - nex[n];
    };

    auto gets = [&](int d, int l, int r, int l1, int r1) {
        vector<i64> s;
        for (int i = l1; i < r1; i++) {
            s.push_back(hs[d][i].get(l, r));
        }
        return s;
    };

    for (int i = 0; i < m; i++) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;

        x1--, y1--;

        cout << getcir(gets(1, x1, x2, y1, y2)) * getcir(gets(0, y1, y2, x1, x2)) << '\n';
    }
    
    return 0;
}

G. 3G网络

C++ Code
#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;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) {
        auto &[x, y] = a[i];
        cin >> x >> y;
    }
    cout << fixed << setprecision(12) << 1.0 / n << '\n';

    return 0;
}

I. 驾驶卡丁车

C++ Code
#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<string> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int sx = 0, sy = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (a[i][j] == '*') {
                sx = i;
                sy = j;
                break;
            }
        }
    }
    int v = 0;
    int dx[] = {-1, -1, +0, +1, +1, +1, +0, -1};
    int dy[] = {+0, +1, +1, +1, +0, -1, -1, -1};
    int d = 0;
    int q;
    cin >> q;
    string s;
    cin >> s;
    for (int i = 0; i < q; i++) {
        if (s[i] == 'U') {
            v = v + 1;
        } else if (s[i] == 'L') {
            d -= 1;
            d += 8;
            d %= 8;
        } else if (s[i] == 'R') {
            d += 1;
            d %= 8;
        } else {
            v = max(v - 1, 0);
        }
        bool ok = 1;
        for (int j = 0; j < v; j++) {
            int tx = sx + dx[d];
            int ty = sy + dy[d];

            if (tx < 0 || ty < 0 || tx >= n || ty >= m || a[tx][ty] == '#') {
                v = 0;
                ok = 0;
                cout << "Crash! " << sx + 1 << ' ' << sy + 1 << '\n';
                break;
            } else if (d % 2 == 1 && a[tx][sy] == '#' && a[sx][ty] == '#') {
                v = 0;
                ok = 0;
                cout << "Crash! " << sx + 1 << ' ' << sy + 1 << '\n';
                break;
            } else {
                sx = tx;
                sy = ty;
            }
        }
        if (ok) {
            cout << sx + 1 << ' ' << sy + 1 << '\n';
        }
    }

    return 0;
}

K. 音乐游戏

C++ Code
#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;
    char ch;
    int ans = 0;
    while (cin >> ch) {
        if (ch == '-') {
            ans++;
        }
    }
    cout << ans << '\n';

    return 0;
}

标签:专场,int,cin,long,i64,++,2021,using,程序设计
From: https://www.cnblogs.com/kiddingma/p/17575047.html

相关文章

  • 2021物业服务力测评成果
    由易居克而瑞主办的「2021物业服务力峰会」在上海召开,克而瑞于现场发布了「2021物业服务力测评成果」,这也给物业行业树立了服务力的风向标。这份榜单含金量较高,都是业主一票一票选出来的,前三甲分别是:万科物业、绿城物业和碧桂园物业。      ......
  • Au2021中文版Audition2021免激活下载 新功能介绍
    AdobeAuditionCS6是一款功能强大的音频编辑器,更是一个专业音频编辑和混合环境。为了方便大家下载使用,winwin7给大家带来的这款AU音频编辑器去除了其他国家的语言,让软件体积变得更小,运行更快,使用更流畅...完善的工具集,其中包含用于创建、混合、编辑和复原音频内容的多轨、波形和光......
  • Java Web 程序设计预习提纲
    以下是JavaWeb程序设计的预习提纲的Markdown格式示例:JavaWeb程序设计预习提纲1.Java基础回顾Java语言基础与面向对象Java类与对象的定义与使用常用数据类型与控制流程异常处理与文件I/O操作2.Servlet基础Servlet概述与生命周期Servlet的请求与响应S......
  • 南京邮电大学《程序设计(上机)》题目[2023-07-21]
    南京邮电大学《程序设计(上机)》题目[2023-07-21]2022-2023学年第1学期程序设计实验指导书胥备17766106600一、 实验前准备硬件:微型计算机一台(个人笔记本电脑)软件:任一C或C++语言开发工具知识准备:1)复习C或者C++语言知识二、 实验目的与任务目的:本课程是在《高级语言程序......
  • 实验五 Java多线程程序设计实验总结
    Java多线程程序设计实验总结引言多线程是计算机科学中重要的概念,它允许同时执行多个任务,从而提高程序的效率和性能。在Java中,多线程被广泛应用于各种场景,例如并发编程、网络编程等。本文将通过实验五的实践经验,介绍Java多线程程序设计的基本原理和常用技巧,并提供代码示例以加深......
  • 7.17~7.18 DP专场
    CF1814EChainChips好久没写这种题了~~不带修时,为了让总距离和最短,考虑让相邻的车互换位置,但如果单纯这样有可能剩下一辆车,那就让相邻的三辆车换一下。发现当车的个数\(x\ge4\)时,都可以拆成\(2\)辆或\(3\)辆车。对应到边就是只能选相邻的一条边或两条边。设\(dp_i\)......
  • C++并行程序设计
    什么是并发?两个或两个以上事件或活动在同一时刻发生。如多个任务在多个CPU或CPU的多个核上同时执行,不存在CPU资源的竞争、等待行为并发程序的意义何在?充分发掘多核处理器的性能,提高计算速率仅供初次学习此内容创作,如有不对请大佬指正前置并行计算基础理论背景......
  • C++语言程序设计任务书[2023-07-18]
    C++语言程序设计任务书[2023-07-18]C++语言程序设计任务书指导老师:李力课程编号:一、学时与学分学时:40学分:2二、实践目的计算机实践是本科计算机基础教学的一个重要环节。它对于巩固学生的计算机基础知识,增强学生的计算机应用水平,改善学生的知识结构,具有重要意义。三、......
  • 【专题】2021互联网广告行业报告PDF合集分享(附原数据表)
    报告链接:https://tecdat.cn/?p=33234原文出处:拓端数据部落公众号2022年,受到疫情干扰,宏观经济面临压力,广告主市场信心不稳定。在这种情况下,广告预算整体下降,更加注重品牌长期价值和在家场景的投放。同时,政策引导和规范同样重要,为推动广告产业数字化转型提供高质量支持。2022年,细......
  • 【专题】2021年中国互联网广告市场洞察报告PDF合集分享(附原数据表)
    报告链接:https://tecdat.cn/?p=33234原文出处:拓端数据部落公众号2022年,受到疫情干扰,宏观经济面临压力,广告主市场信心不稳定。在这种情况下,广告预算整体下降,更加注重品牌长期价值和在家场景的投放。同时,政策引导和规范同样重要,为推动广告产业数字化转型提供高质量支持。2022年,细......