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…...

XCTF-web-easyupload
试了试php,php7,pht,phtml等,都没有用 尝试.user.ini 抓包修改将.user.ini修改为jpg图片 在上传一个123.jpg 用蚁剑连接,得到flag...
<6>-MySQL表的增删查改
目录 一,create(创建表) 二,retrieve(查询表) 1,select列 2,where条件 三,update(更新表) 四,delete(删除表…...

聊聊 Pulsar:Producer 源码解析
一、前言 Apache Pulsar 是一个企业级的开源分布式消息传递平台,以其高性能、可扩展性和存储计算分离架构在消息队列和流处理领域独树一帜。在 Pulsar 的核心架构中,Producer(生产者) 是连接客户端应用与消息队列的第一步。生产者…...

【大模型RAG】Docker 一键部署 Milvus 完整攻略
本文概要 Milvus 2.5 Stand-alone 版可通过 Docker 在几分钟内完成安装;只需暴露 19530(gRPC)与 9091(HTTP/WebUI)两个端口,即可让本地电脑通过 PyMilvus 或浏览器访问远程 Linux 服务器上的 Milvus。下面…...

定时器任务——若依源码分析
分析util包下面的工具类schedule utils: ScheduleUtils 是若依中用于与 Quartz 框架交互的工具类,封装了定时任务的 创建、更新、暂停、删除等核心逻辑。 createScheduleJob createScheduleJob 用于将任务注册到 Quartz,先构建任务的 JobD…...

MySQL 8.0 OCP 英文题库解析(十三)
Oracle 为庆祝 MySQL 30 周年,截止到 2025.07.31 之前。所有人均可以免费考取原价245美元的MySQL OCP 认证。 从今天开始,将英文题库免费公布出来,并进行解析,帮助大家在一个月之内轻松通过OCP认证。 本期公布试题111~120 试题1…...
CRMEB 框架中 PHP 上传扩展开发:涵盖本地上传及阿里云 OSS、腾讯云 COS、七牛云
目前已有本地上传、阿里云OSS上传、腾讯云COS上传、七牛云上传扩展 扩展入口文件 文件目录 crmeb\services\upload\Upload.php namespace crmeb\services\upload;use crmeb\basic\BaseManager; use think\facade\Config;/*** Class Upload* package crmeb\services\upload* …...

IoT/HCIP实验-3/LiteOS操作系统内核实验(任务、内存、信号量、CMSIS..)
文章目录 概述HelloWorld 工程C/C配置编译器主配置Makefile脚本烧录器主配置运行结果程序调用栈 任务管理实验实验结果osal 系统适配层osal_task_create 其他实验实验源码内存管理实验互斥锁实验信号量实验 CMISIS接口实验还是得JlINKCMSIS 简介LiteOS->CMSIS任务间消息交互…...
代理篇12|深入理解 Vite中的Proxy接口代理配置
在前端开发中,常常会遇到 跨域请求接口 的情况。为了解决这个问题,Vite 和 Webpack 都提供了 proxy 代理功能,用于将本地开发请求转发到后端服务器。 什么是代理(proxy)? 代理是在开发过程中,前端项目通过开发服务器,将指定的请求“转发”到真实的后端服务器,从而绕…...

安全突围:重塑内生安全体系:齐向东在2025年BCS大会的演讲
文章目录 前言第一部分:体系力量是突围之钥第一重困境是体系思想落地不畅。第二重困境是大小体系融合瓶颈。第三重困境是“小体系”运营梗阻。 第二部分:体系矛盾是突围之障一是数据孤岛的障碍。二是投入不足的障碍。三是新旧兼容难的障碍。 第三部分&am…...