VP Codeforces Round 944 (Div 4)

news2024/9/22 10:05:05

感受:

A~G 其实都不难,都可以试着补起来。 H看到矩阵就放弃了。

A题:

思路:

打开编译器

代码:

#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
const int N = 1e8;
inline void solve() {
    int a, b; cin >> a >> b;
    if (a > b) swap(a, b);
    cout << a << ' ' << b << endl;
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tt; cin >> tt;
    while (tt -- ) solve();
    return 0;
}

B题:

思路:

 思维一点。如果这个字符串不是全都一样的话,那么一定就是输出Yes的,具体在实现。如果在后面遇到过与开头不一样的字符,我们进行交换输出即可。

代码:

#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
const int N = 1e8;
inline void solve() {
    string a; cin >> a;
    if (a.size() == 1) return cout << "NO\n", void();
    char c = a[0];
    for (int i = 1; i < a.size(); i ++ ) {
        if (a[i] != c) {
            swap(a[i], a[0]);
            cout << "YES" << endl;
            cout << a << endl;
            return;
        }
    }
    cout << "NO" << endl;
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tt; cin >> tt;
    while (tt -- ) solve();
    return 0;
}

C题:

思路:

要判断是否相交,即要满足以下条件:(假设我们已经排好序)

1.第一条线段的开头小于第二条线段的开头

2.第一条线段的末尾大于第二条线段的开头

3.第二条线段的末尾大于第一条线段的末尾

排序过程可以想象成将12-1这段拆开来,将环变成线段。

代码:

#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;
const int N = 1e8;
inline void solve() {
    PII a, b;
    cin >> a.x >> a.y;
    cin >> b.x >> b.y;
    if (a.x > a.y) swap(a.x, a.y);
    if (b.x > b.y) swap(b.x, b.y);
    if (a > b) swap(a, b);
    if (a.x < b.x && b.x < a.y && a.y < b.y) cout << "YES\n";
    else cout << "NO\n";
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tt; cin >> tt;
    while (tt -- ) solve();
    return 0;
}

 D题:

思路:

我们要尽可能少剪,那么可能是剪一连串的0或者1.

然后我们进行分类讨论

如果开头是0,有0001111这样子的子串,我们是不是还可以少剪一个?

如果开头是1,有1100111这样子的子串,我们还可以少剪一个。

代码:

#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
#define x first
#define y second

using namespace std;
typedef pair<int, int> PII;
const int N = 1e8;

inline void solve() {
    string a; cin >> a;
    int n = a.size();
    if (n == 1) return cout << 1 << endl, void();
    // 001001001
    int cnt = 1;
    for (int i = 1; i < n; i ++ ) {
        if (a[i] != a[i - 1]) cnt += 1;
    }
    if (a[0] == '0') {
        cout << (cnt > 1 ? cnt - 1 : 1) << endl;
    }else {
        cout << (cnt > 2 ? cnt - 1 : cnt) << endl;
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tt; cin >> tt;
    while (tt -- ) solve();
    return 0;
}

E题:

思路:

速度是匀速的,主要问题是确定在哪段,我们直接二分即可。

代码:

#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
#define x first
#define y second

using namespace std;
typedef pair<int, int> PII;
const int N = 1e8;

inline void solve() {
    int n, k, q; cin >> n >> k >> q;
    vector<PII> a(k + 2);
    a[1].first = a[1].second = 0;
    for (int i = 2; i <= k + 1; i ++ ) cin >> a[i].first;
    for (int i = 2; i <= k + 1; i ++ ) cin >> a[i].second;
    while (q -- ) {
        int x; cin >> x;
        int l = 1, r = k + 2;
        while (l + 1 != r) {
            int mid = (l + r) >> 1;
            if (a[mid].first < x) l = mid;
            else r = mid;
        }
        int len = a[r].second - a[l].second;
        int d = a[r].first - a[l].first;
        int t = x - a[l].first;
        int ans = a[l].second + t * len / d;
        cout << ans << ' ';
    }
    cout << endl;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tt; cin >> tt;
    while (tt -- ) solve();
    return 0;
}

F题: 

思路:

饶有兴趣的是,它是r的总和小于1e5.

所以我们可以直接枚举 x。

那么我们为什么要枚举 x 呢?

因为当我们移动 x 的时候,y的值也在进行变动

x^{2} + y^{2} = r ^{2}

y的值即可以用二分求出来了。

代码:

#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
#define x first
#define y second

using namespace std;
typedef pair<int, int> PII;
const int N = 1e5 + 9;
inline int fac(int t) {
    int ans = 0;
    for (int x = 0; x < t; x ++ ) {
        int now = t * t - x * x;
        int l = -1, r = t;
        while (l + 1 != r) {
            int mid = (l + r) >> 1;
            if (mid * mid < now) l = mid;
            else r = mid;
        }
        ans += r;
    }
    return ans;
}

inline void solve() {
    int r; cin >> r;
    int ans = fac(r + 1) - fac(r);
    ans *= 4;
    ans -= 4;
    cout << ans << endl;
}
inline void pre_work() {

}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    pre_work();
    int tt; cin >> tt;
    while (tt -- ) solve();
    return 0;
}

G题:

思路:

一个数 x 跟哪些数异或起来会小于等于3?

答案是 x, x ^ 1, x ^ 2, x ^ 3

因为二进制从第三位开始就必须要一模一样了。

交换可以用map存数量,用的时候减去即可。

代码:

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define int long long
#define x first
#define y second

using namespace std;
typedef pair<int, int> PII;
const int N = 1e5 + 9;

inline void solve() {
    int n; cin >> n;
    vector<int> a(n + 1);
    map<int, int> cnt;
    for (int i = 1; i <= n; i ++ ) {
        cin >> a[i];
        cnt[a[i]] += 1;
    }
    for (int i = 1; i <= n; i ++ ) {
        int b[4];
        b[0] = a[i], b[1] = a[i] ^ 1, b[2] = a[i] ^ 2, b[3] = a[i] ^ 3;
        sort(b, b + 4);
        for (int j = 0; j < 4; j ++ ) {
            if (cnt[b[j]]) {
                cout << b[j] << ' ';
                cnt[b[j]] -= 1;
                break;
            }
        }
    }
    cout << endl;
}
inline void pre_work() {

}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    pre_work();
    int tt; cin >> tt;
    while (tt -- ) solve();
    return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1679898.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

基于Springboot的学生心理压力咨询评判(有报告)。Javaee项目,springboot项目。

演示视频&#xff1a; 基于Springboot的学生心理压力咨询评判&#xff08;有报告&#xff09;。Javaee项目&#xff0c;springboot项目。 项目介绍&#xff1a; 采用M&#xff08;model&#xff09;V&#xff08;view&#xff09;C&#xff08;controller&#xff09;三层体系…

【Unity之FairyGUI】你了解FGUI吗,跨平台多功能高效UI插件

&#x1f468;‍&#x1f4bb;个人主页&#xff1a;元宇宙-秩沅 &#x1f468;‍&#x1f4bb; hallo 欢迎 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! &#x1f468;‍&#x1f4bb; 本文由 秩沅 原创 &#x1f468;‍&#x1f4bb; 收录于专栏&#xff1a;就业…

免费体验GPT-4o这5大功能,非常好用!

这几天&#xff0c;OpenAI发布了新的GPT版本&#xff0c;GPT-4o&#xff0c;比GPT4更加智能也更快。 据说&#xff0c;GPT-4o在文本、推理和编码智能方面实现了GPT-4 Turbo级别的性能&#xff0c;在多语言、文本、音频和视觉功能方面甚至超过了市面上所有同类产品。 有几个亮点…

Anaconda安装-超详细版(2024)

扫盲&#xff1a;先装Python还是先装anaconda? 安装anaconda即可&#xff0c;不需要单独装python anaconda 是一个python的发行版&#xff0c;包括了python和很多常见的软件库, 和一个包管理器conda。 一、下载Anaconda 安装包&#xff08;官网和国内镜像资源&#xff09; …

SpringBoot之远程调用的三大方式

为什么要使用远程调用&#xff1f; SpringBoot不仅继承了Spring框架原有的优秀特性&#xff0c;而且还通过简化配置来进一步简化了Spring应用的整个搭建和开发过程。在Spring-Boot项目开发中&#xff0c;存在着本模块的代码需要访问外面模块接口&#xff0c;或外部url链接的需求…

基于SpringBoot设计模式之创建型设计模式·工厂方法模式

文章目录 介绍开始架构图样例一定义工厂定义具体工厂&#xff08;上衣、下装&#xff09;定义产品定义具体生产产品&#xff08;上衣、下装&#xff09; 测试样例 总结优点缺点与抽象工厂不同点 介绍 在 Factory Method模式中&#xff0c;父类决定实例的生成方式&#xff0c;但…

Git使用(3):版本管理

一、查看历史 编写一个java类进行测试 选择Git -> Show Git Log查看日志。 第一次修改推送到远程仓库了&#xff0c;所以有origin&#xff08;远程仓库地址&#xff09;&#xff0c;第二次修改只提交到本地仓库所以没有。 二、版本回退 1、本地回退 在要回退的版本上右键&a…

嵌入式学习-输入捕获

简介 框图介绍 输入通道部分 比较捕获寄存器与事件生成 相关寄存器

Linux基本工具的使用

什么是工具&#xff1f; 在Linux中&#xff0c;工具的本质也是指令&#xff0c;只是因为这些指令与我们的开发的关系不是很大&#xff0c;所以就被称为工具 1 软件包管理器yum 在我们的Windows上如果想要安装软件&#xff0c;第一件事就是要先下载软件安装包&#xff0c;然后…

Linux的常用指令 和 基础知识穿插巩固(巩固知识必看)

目录 前言 ls ls 扩展知识 ls -l ls -a ls -al cd cd 目录名 cd .. cd ~ cd - pwd 扩展知识 路径 / cp [选项] “源文件名” “目标文件名” mv [选项] “源文件名” “目标文件名” rm 作用 用法 ./"可执行程序名" mkdir rmdir touch m…

海外住宅IP介绍

住宅IP&#xff0c;通俗的来讲就是分配给家庭的IP地址&#xff0c;ISP默认分配用户为家庭用户&#xff0c;其真实性与安全性都有一定保障。海外住宅IP是指由海外互联网服务提供商分配给家庭用户的IP地址&#xff0c;IP地址通常是静态的&#xff0c;稳定的&#xff0c;可以为用户…

U盘中毒文件变乱码?揭秘原因与高效恢复方法!

在日常使用U盘的过程中&#xff0c;有时我们会遭遇到一个非常棘手的问题——文件突然出现乱码。当你满怀期待地插入U盘&#xff0c;准备打开某个重要文件时&#xff0c;却发现文件名或内容变成了一堆无法识别的字符&#xff0c;这种心情无异于晴天霹雳。乱码文件不仅影响了我们…

鸿蒙生态融合进行时!菊风启动适配HarmonyOS NEXT,赋能原生应用实时

​​今日话题 鸿蒙HarmonyOS NEXT 自华为公开宣布鸿蒙 HarmonyOS NEXT 系统以来&#xff0c;该系统受到了业内广泛关注&#xff0c;和以往鸿蒙系统不同的是该系统底座完全由华为自研&#xff0c;摒弃了 Linux 内核和安卓 AOSP 代码&#xff0c;仅兼容鸿蒙内核及鸿蒙系统的应用…

【多模态】31、Qwen-VL | 一个开源的全能的视觉-语言多模态大模型

文章目录 一、背景二、方法2.1 模型架构2.2 输入和输出2.3 训练 三、效果3.1 Image Caption 和 General Visual Question Answering3.2 Text-oriented Visual Question Answering3.3 Refer Expression Comprehension3.4 视觉-语言任务的少样本学习3.5 真实世界用户行为中的指令…

windows部署腾讯tmagic-editor03-DSL 解析渲染

创建项目 将上一教程中的editor-runtime和hello-editor复制过来 概念 实现 创建hello-ui目录 渲染节点 在hello-ui下创建 Component.vue 文件 由于节点的type是由业务自行定义的&#xff0c;所以需要使用动态组件渲染&#xff0c;在vue下可以使用component组件来实现 c…

20240511每日运维----聊聊nignx改配置所有的nginx改完unknow

1、改配置所有的nginx改完unknow src/core/nginx.h src/http/ngx_http_header_filter_module.c src/http/ngx_http_special_response.c src/http/v2/ngx_http_v2_filter_module.c 2、make 3、去objs里面把nginx文件替换过去sbin/nginx

高质量英文文献应该如何查找并且阅读?

1. 查找 使用谷歌学术进行论文关键字检索&#xff0c;查找高度匹配的论文。这里我们可以选择年限等信息进行筛选。作为研究者我们一般选择近三年的文章进行阅读。这里谷歌学术需要科学上网&#xff0c;请大家自行解决。 https://scholar.google.com/ 2. 查看期刊等级 我们查…

深度学习设计模式之抽象工厂模式

文章目录 前言一、介绍二、详细分析1.核心组成2.实现步骤3.代码示例4.优缺点优点缺点 5.使用场景 总结 前言 本文主要学习抽象工厂模式&#xff0c;抽象工厂模式创建的是对象家族&#xff0c;比如&#xff1a;苹果是一个产品&#xff0c;但是他不单单只生产手机&#xff0c;还…

【C语言】必备Linux命令和C语言基础

&#x1f31f;博主主页&#xff1a;我是一只海绵派大星 &#x1f4da;专栏分类&#xff1a;嵌入式笔记 ❤️感谢大家点赞&#x1f44d;收藏⭐评论✍️ 目录 一、文件和目录相关命令 Linux 的文件系统结构 文件系统层次结构标准FHS pwd命令 ls 列目录内容 文件的权限 c…

libsndfile读取wav文件基本属性

本文的目的是提供一种方法读取wav文件的基本属性&#xff1a;音频帧数&#xff0c;格式、通道数和采样率信息。 代码如下所示&#xff1a; #include <iostream> #include <QDebug> #include "sndfile.h"using namespace std;int main() {// 初始化 ALS…