Hello 2024(A~D,F1)
新年坐大牢
A - Wallet Exchange
题意:共有俩钱包,每回合从其中一个钱包中拿走一块钱,谁拿走最后一块钱谁赢。
思路:奇偶讨论即可。
// Problem: A. Wallet Exchange
// Contest: Codeforces - Hello 2024
// URL: https://codeforces.com/contest/1919/problem/0
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second
#define endl '\n'
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){return b > 0 ? gcd(b , a % b) : a;
}LL lcm(LL a , LL b){return a / gcd(a , b) * b;
}
int n , m;
vector<int>a(N , 0);
void init(int n){for(int i = 0 ; i <= n ; i ++){a[i] = 0;}
}
void solve()
{LL a , b;cin >> a >> b;LL t = a + b;if(t & 1){cout <<"Alice\n";} else{cout<<"Bob\n";}
}
int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);int t=1;cin>>t;while(t--){solve();}return 0;
}
B - Plus-Minus Split
题意:给定一个"+-"串,其中"+"代表了‘’+1“,"-”代表了“-1”.你需要将整个串分成若干份,每一份的价值为子串所代表的数的绝对值,求整个串的最小价值.
思路:贪心,其实整个串的价值就是最小价值.
// Problem: B. Plus-Minus Split
// Contest: Codeforces - Hello 2024
// URL: https://codeforces.com/contest/1919/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second
#define endl '\n'
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){return b > 0 ? gcd(b , a % b) : a;
}LL lcm(LL a , LL b){return a / gcd(a , b) * b;
}
int n , m;
vector<int>a(N , 0);
void init(int n){for(int i = 0 ; i <= n ; i ++){a[i] = 0;}
}
void solve()
{cin >> n;int ans = 0;string s;cin >> s;for(int i = 0 ; i < n ; i ++){if(s[i] == '+'){ans++;}else{ans--;}} cout << abs(ans) << endl;
}
int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);int t=1;cin>>t;while(t--){solve();}return 0;
}
C - Grouping Increases
题意:给定一个数组,要求将其分成两部分,要求每部分中元素在原数组中的相对位置不能改变,每一部分的价值为:这一部分中,前一个数小于后一个数的个数.求两部分价值之和的最小值。
思路:可以想到,由于无法改变相对顺序,我们需要从前往后的插入元素.而每一部分的最后一个元素值应当越大越好。因此我们每次插入元素只需要插入到两个部分中尾数小的那部分即可,然后再算出总共价值就是最小价值.
// Problem: C. Grouping Increases// Contest: Codeforces - Hello 2024// URL: https://codeforces.com/contest/1919/problem/C// Memory Limit: 256 MB// Time Limit: 1000 ms// // Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>using namespace std;#define LL long long#define pb push_back#define x first#define y second #define endl '\n'const LL maxn = 4e05+7;const LL N = 5e05+10;const LL mod = 1e09+7;const int inf = 0x3f3f3f3f;const LL llinf = 5e18;typedef pair<int,int>pl;priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆priority_queue<LL> ma;//大根堆LL gcd(LL a, LL b){return b > 0 ? gcd(b , a % b) : a;}LL lcm(LL a , LL b){return a / gcd(a , b) * b;}int n , m;vector<int>a(N , 0);void init(int n){for(int i = 0 ; i <= n ; i ++){a[i] = 0;}}void solve() {int rear[2] = {inf , inf};int n;cin >> n;for(int i = 0 ; i < n ; i ++){cin >> a[i];} int ans = 0;for(int i = 0 ; i < n ; i ++){int cnt = 0;for(int j = 0 ; j < 2 ; j ++){cnt += (rear[j] < a[i]);}if(cnt == 0){if(rear[0] < rear[1]){rear[0] = a[i];}else{rear[1] = a[i];}}else if(cnt == 1){if(rear[0] < a[i]){rear[1] = a[i];}else{rear[0] = a[i];}}else{if(rear[0] < rear[1]){rear[0] = a[i];}else{rear[1] = a[i];}ans++;}}cout << ans << endl;} int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);int t=1;cin>>t;while(t--){solve();}return 0;}
F1 - Wine Factory (Easy Version)
题意:
思路:由于固定了,也就是前一个水塔的水必定能全部流入后一个水塔.
这是一开始的想法,然后发现整个过程其实是一个区间从前往后合并的过程,因此考虑用线段树去解决区间合并问题。
接下来考虑如何合并:若前面区间还有剩余的水,那么可以由后面的魔法师去变为葡萄酒,因此我们需要知道的是,区间中还剩多少水和区间中的魔法师还剩多少能量。同时我们还可以统计转换了多少葡萄酒。
每次只需要单点修改和整个区间查询就行了。
// Problem: F1. Wine Factory (Easy Version)
// Contest: Codeforces - Hello 2024
// URL: https://codeforces.com/contest/1919/problem/F1
// Memory Limit: 512 MB
// Time Limit: 5000 ms
//
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second
#define endl '\n'
#define int long long
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){return b > 0 ? gcd(b , a % b) : a;
}
vector<int>a(N , 0);
vector<int>b(N, 0);
vector<int>c(N, 0);
struct info{LL Res;//剩余多少水LL Res_ma;//魔法师还剩余多少能量LL Value;//价值friend info operator + (info a ,info b){info c;c.Value = a.Value + b.Value;c.Res_ma = b.Res_ma + a.Res_ma;if(a.Res > 0){int d = min(a.Res , b.Res_ma);c.Res_ma -= d;c.Value += d;a.Res -= d;}c.Res = a.Res + b.Res;return c;}
};
struct node{info val;
} seg[N * 4];
struct SegTree{void update(int id){seg[id].val = seg[id * 2].val + seg[id * 2 + 1].val;}void build(int id, int l, int r){if (l == r) {seg[id].val = {max(0 * 1LL ,a[l] - b[l]) , max(0 * 1LL , b[l] - a[l]) , min(a[l] , b[l])};}else{int mid = (l + r) / 2;build(id * 2, l, mid);build(id * 2 + 1, mid + 1, r);update(id);}}void modify(int id, int l, int r, int ql, int qr){if (l == ql && r == qr){seg[id].val = {max(0 * 1LL ,a[l] - b[l]) , max(0 * 1LL , b[l] - a[l]) , min(a[l] , b[l])};return;}if (ql > r || qr < l) // 区间无交集return; // 剪枝int mid = (l + r) / 2;if (qr <= mid) modify(id * 2, l, mid, ql, qr);else if (ql > mid) modify(id * 2 + 1, mid + 1, r, ql, qr);else{modify(id * 2, l, mid, ql, mid);modify(id * 2 + 1, mid + 1, r, mid + 1, qr);}update(id);}info query(int id, int l, int r, int ql, int qr){if (ql == l && qr == r) return seg[id].val;int mid = (l + r) / 2;if (qr <= mid) return query(id * 2, l, mid, ql, qr);else if (ql > mid) return query(id * 2 + 1, mid + 1, r, ql, qr);else{return query(id * 2, l, mid, ql, mid) + query(id * 2 + 1, mid + 1, r, mid + 1, qr);}}
};
LL lcm(LL a , LL b){return a / gcd(a , b) * b;
}
int n , m;
void solve()
{cin >> n >> m;for(int i = 1 ; i <= n ; i ++){cin >> a[i];}for(int i = 1 ; i <= n ; i ++){cin >> b[i];}for(int i = 1 ; i < n ; i ++){cin >> c[i];}SegTree segTree;segTree.build(1 , 1 , n);for(int i = 0 ; i < m ; i ++){int q , x , y , z;cin >> q >> x >> y >> z;a[q] = x;b[q] = y;segTree.modify(1 , 1 , n , q , q);cout << segTree.query(1 , 1 , n , 1 , n).Value << endl;}
}
signed main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);int t=1;
// cin>>t;while(t--){solve();}return 0;
}
D - 01 Tree
题意:先有一颗未知的完整二叉树,非叶子结点的两条与子节点相连的边权一个为0,另一个为1.如今给出了根据dfs序的叶子结点的权值序列,求能否还原出一颗完整二叉树.定义结点的权值为该节点到根节点的边权之和.
思路:可以发现:同一个父亲的两个叶子结点的权值只差了1,且两个叶子结点中小的那个就是父节点的权值.也就是说,dfs序中若相邻两个数差了1,那么这两个数就是同一个父亲结点的。由此我们可以将同一个父亲的两个叶子结点中大的删除,小的保留,这样就相当于将两个叶子结点给删除了.最后若只剩下一个点没有被删除,且这个点为0,那么就代表了能够通过删除操作只保留一个顶点,反过来也就是说通过这个序列能够形成一个完整二叉树.
// Problem: D. 01 Tree
// Contest: Codeforces - Hello 2024
// URL: https://codeforces.com/contest/1919/problem/D
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second
#define endl '\n'
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){return b > 0 ? gcd(b , a % b) : a;
}LL lcm(LL a , LL b){return a / gcd(a , b) * b;
}
int n , m;
vector<int>a(N , 0);
void init(int n){for(int i = 0 ; i <= n ; i ++){a[i] = 0;}
}
void solve()
{cin >> n;for(int i = 1; i <= n ; i ++){cin >> a[i];}a[0] = a[n + 1] = -inf;vector<int>nex(n + 5 , 0) , pre(n + 5 , 0);for(int i = 1; i <= n ; i ++){nex[i] = i + 1;pre[i] = i - 1;}auto check = [&](int x){return (a[pre[x]] == a[x] - 1) || (a[nex[x]] == a[x] - 1);};vector<int>in(n + 5 , 0);priority_queue<pair<int,int>>ma;for(int i = 1 ; i <= n ; i ++){if(check(i)){in[i] = 1;ma.push({a[i] , i});}}while(!ma.empty()){auto tmp = ma.top();ma.pop();int pos = tmp.y;nex[pre[pos]] = nex[pos];pre[nex[pos]] = pre[pos];if(!in[nex[pos]] && check(nex[pos])){in[nex[pos]] = 1;ma.push({a[nex[pos]] , nex[pos]});}if(!in[pre[pos]] && check(pre[pos])){in[pre[pos]] = 1;ma.push({a[pre[pos]] , pre[pos]});}}int mi = n , bad = 0;for(int i = 1 ; i <= n ; i ++){bad += (!in[i]);mi = min(mi , a[i]);}if(bad == 1 && mi == 0){cout <<"YES\n";}else{cout <<"NO\n";}
}
int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);int t=1;cin>>t;while(t--){solve();}return 0;
}
相关文章:
Hello 2024(A~D,F1)
新年坐大牢 A - Wallet Exchange 题意:共有俩钱包,每回合从其中一个钱包中拿走一块钱,谁拿走最后一块钱谁赢。 思路:奇偶讨论即可。 // Problem: A. Wallet Exchange // Contest: Codeforces - Hello 2024 // URL: https://cod…...

Python+Torch+FasterCNN网络目标检测识别
程序示例精选 PythonTorchFasterCNN网络目标检测识别 如需安装运行环境或远程调试,见文章底部个人QQ名片,由专业技术人员远程协助! 前言 这篇博客针对《PythonTorchFasterCNN网络目标检测识别》编写代码,代码整洁,规…...
v8 pwn利用合集
文章目录 前置知识JS Object 相关Ignition 相关JIT - turboFan 相关starCTF2019 OOB【越界读写map字段】googleCTF2018 jit【浮点数精度丢失导致越界读写】数字经济线下 Browser【Object::toNumber中callback导致的越界写】前置知识 JS Object 相关 V8 中的对象表示 ==> 基…...

JVM:字节码
JVM:字节码 前言1. JVM概述1.1 JVM vs JDK vs JRE1.1.1 JVM1.1.2 JDK1.1.2.1 常用的JDK8是Oracle JDK 还是 OpenJDK 1.1.3 JRE1.1.4 三者之间的关系与区别 1.2 什么是字节码?采用字节码的好处是什么?1.3 Java 程序从源代码到运行的过程1.4 JVM的生命周期1.5 JVM架…...

常见网络设备及功能详解
网络设备 - 交换机 交换机:距离终端用户最近的设备,用于终端用户接入网络、对数据帧进行交换等。 交换机的功能: 终端设备(PC、服务器等)的网络接入二层交换(Layer 2 Switching) 网络设备 - …...

Python教程(20)——python面向对象编程基本概念
面向对象 类和对象初始化方法属性和方法self关键字继承多态 面向对象(Object-oriented)是一种常用的程序设计思想,它以对象作为程序的基本单元,将数据和操作封装在一起,通过对象之间的交互来实现程序的功能。 在面向对…...

C# Winform教程(一):MD5加密
1、介绍 在C#中,MD5(Message Digest Algorithm 5)是一种常用的哈希函数,用于将任意长度的数据转换为固定长度的哈希值(通常是128位)。MD5广泛用于校验数据完整性、密码存储等领域。 2、示例 创建MD5加密…...

Mongodb使用指定索引删除数据
回顾Mongodb删除语法 db.collection.deleteMany(<filter>,{writeConcern: <document>,collation: <document>,hint: <document|string>} ) 删除语法中,除了指定过滤器外,还可以指定写入策略,字符序和使用的索引。 …...

虾皮怎么选品:虾皮(Shopee)跨境电商业务成功的关键步骤
在虾皮(Shopee)平台上进行跨境电商业务,选品是至关重要的一环。有效的选品策略可以帮助卖家更好地了解市场需求,提高销售业绩和客户满意度。以下是一些成功的选品策略,可以帮助卖家在虾皮平台上取得更好的业务成绩。 先…...
QML —— 使用Qt虚拟键盘示例(附完整源码)
示例效果 使用"虚拟键盘"注意 (例子的Qt版本:5.12.4) 注意一: /* 必须在main.cpp开始处加入如下代码,否则无法使用"虚拟键盘" */ qputenv(“QT_IM_MODULE”,QByteArray(“qtvirtualkeybo…...

Nacos 持久化及集群的搭建【微服务】
文章目录 一、统一配置管理二、微服务配置拉取三、配置热更新四、多环境共享配置五、Nacos 集群搭建1. 集群结构2. 初始化数据库3. 搭建集群 六、Nginx 反向代理七、启动项目测试 一、统一配置管理 案例练习的时候我们只有两个微服务,管理起来非常简单,但…...

win10下vscode+cmake编译C代码操作详解
0 工具准备 1.Visual Studio Code 1.85.1 2.cmake 3.24.01 前言 当我们只有一个.c文件时直接使用vscodeCode Runner插件即可完成编译,如果我们的工程很复杂包含多个.c文件时建议使用cmake来生成对应的make,指导编译器完成编译,否则会提示各…...

网络安全红队常用的攻击方法及路径
一、信息收集 收集的内容包括目标系统的组织架构、IT资产、敏感信息泄露、供应商信息等各个方面,通过对收集的信息进行梳理,定位到安全薄弱点,从而实施下一步的攻击行为。 域名收集 1.备案查询 天眼查爱企查官方ICP备案查询 通过以上三个…...
【基于openGauss2.1.0企业版安装X-Tuner参数调优工具】
【基于openGauss2.1.0企业版安装X-Tuner参数调优工具】 一、前提条件二、安装X-Tuner 2.1.0: 一、前提条件 已安装了openGauss2.1.0企业版 二、安装X-Tuner 2.1.0: 以root用户登录到服务器 安装以下依赖: yum -y groupinstall "Development tools" yum…...

SpringBoot+Vue轻松实现考试管理系统
简介 本系统基于 Spring Boot 搭建的方便易用、高颜值的教学管理平台,提供多租户、权限管理、考试、练习、在线学习等功能。主要功能为在线考试、练习、刷题,在线学习。课程内容支持图文、视频,考试类型支持考试、练习、问卷。 源码下载 网…...
详解Keras:keras.preprocessing.image
keras.preprocessing.image Keras 库中的一个模块,用于处理和增强图像数据,它提供了一些实用的函数,如图像的加载、预处理、增强等。 常用函数 1、load_img 用于加载图像文件,并返回一个 NumPy 数组表示该图像 示例 from ker…...

来瞅瞅Java 11都有啥新特性
第1章:引言 大家好,我是小黑!今天小黑要和咱们聊聊Java 11,这个在Java发展史上占有一席之地的版本。说起Java,咱们都知道,它是一门历史悠久又持续发展的编程语言。Java不仅因其“一次编写,到处…...
Copilot在IDEA中的应用:提升编码效率的得力助手
Copilot在IDEA中的应用:提升编码效率的得力助手 前言: 欢迎来到本篇博客,今天我们将深入探讨 GitHub Copilot 在 IntelliJ IDEA 中的应用。GitHub Copilot 是一款由 GitHub 与 OpenAI 共同开发的人工智能代码生成工具,它能够根据上下文提示…...
【Python】Excel不同sheet另存为不同CSV
我有一个excel,内有不同sheet,现在批量生成不通csv文件,并以sheet名命名,或根据sheet名调整命名。 # 读取新的Excel文件 df pd.read_excel(rD:\itm\data.xlsx, sheet_nameNone)# 遍历每个sheet,将其另存为不同的CSV文…...

软件测试|深入学习 Docker Logs
简介 Docker 是一种流行的容器化技术,它能够帮助用户将应用程序及其依赖项打包成一个可移植的容器。Docker logs 是 Docker 提供的用于管理容器日志的命令,本文将深入学习 Docker logs 的使用和管理,帮助用户更好地监测和解决容器问题。 Do…...

业务系统对接大模型的基础方案:架构设计与关键步骤
业务系统对接大模型:架构设计与关键步骤 在当今数字化转型的浪潮中,大语言模型(LLM)已成为企业提升业务效率和创新能力的关键技术之一。将大模型集成到业务系统中,不仅可以优化用户体验,还能为业务决策提供…...

日语AI面试高效通关秘籍:专业解读与青柚面试智能助攻
在如今就业市场竞争日益激烈的背景下,越来越多的求职者将目光投向了日本及中日双语岗位。但是,一场日语面试往往让许多人感到步履维艰。你是否也曾因为面试官抛出的“刁钻问题”而心生畏惧?面对生疏的日语交流环境,即便提前恶补了…...

(十)学生端搭建
本次旨在将之前的已完成的部分功能进行拼装到学生端,同时完善学生端的构建。本次工作主要包括: 1.学生端整体界面布局 2.模拟考场与部分个人画像流程的串联 3.整体学生端逻辑 一、学生端 在主界面可以选择自己的用户角色 选择学生则进入学生登录界面…...
五年级数学知识边界总结思考-下册
目录 一、背景二、过程1.观察物体小学五年级下册“观察物体”知识点详解:由来、作用与意义**一、知识点核心内容****二、知识点的由来:从生活实践到数学抽象****三、知识的作用:解决实际问题的工具****四、学习的意义:培养核心素养…...

UR 协作机器人「三剑客」:精密轻量担当(UR7e)、全能协作主力(UR12e)、重型任务专家(UR15)
UR协作机器人正以其卓越性能在现代制造业自动化中扮演重要角色。UR7e、UR12e和UR15通过创新技术和精准设计满足了不同行业的多样化需求。其中,UR15以其速度、精度及人工智能准备能力成为自动化领域的重要突破。UR7e和UR12e则在负载规格和市场定位上不断优化…...
Spring AI与Spring Modulith核心技术解析
Spring AI核心架构解析 Spring AI(https://spring.io/projects/spring-ai)作为Spring生态中的AI集成框架,其核心设计理念是通过模块化架构降低AI应用的开发复杂度。与Python生态中的LangChain/LlamaIndex等工具类似,但特别为多语…...
Device Mapper 机制
Device Mapper 机制详解 Device Mapper(简称 DM)是 Linux 内核中的一套通用块设备映射框架,为 LVM、加密磁盘、RAID 等提供底层支持。本文将详细介绍 Device Mapper 的原理、实现、内核配置、常用工具、操作测试流程,并配以详细的…...
Python 包管理器 uv 介绍
Python 包管理器 uv 全面介绍 uv 是由 Astral(热门工具 Ruff 的开发者)推出的下一代高性能 Python 包管理器和构建工具,用 Rust 编写。它旨在解决传统工具(如 pip、virtualenv、pip-tools)的性能瓶颈,同时…...
管理学院权限管理系统开发总结
文章目录 🎓 管理学院权限管理系统开发总结 - 现代化Web应用实践之路📝 项目概述🏗️ 技术架构设计后端技术栈前端技术栈 💡 核心功能特性1. 用户管理模块2. 权限管理系统3. 统计报表功能4. 用户体验优化 🗄️ 数据库设…...
Caliper 负载(Workload)详细解析
Caliper 负载(Workload)详细解析 负载(Workload)是 Caliper 性能测试的核心部分,它定义了测试期间要执行的具体合约调用行为和交易模式。下面我将全面深入地讲解负载的各个方面。 一、负载模块基本结构 一个典型的负载模块(如 workload.js)包含以下基本结构: use strict;/…...