【每日一题丨2025年5.12~5.18】排序相关题

news2025/5/22 6:44:42

在这里插入图片描述

个人主页:Guiat
归属专栏:每日一题

在这里插入图片描述

文章目录

  • 1. 【5.12】P1068 [NOIP 2009 普及组] 分数线划定
  • 2. 【5.13】P5143 攀爬者
  • 3. 【5.14】P12366 [蓝桥杯 2022 省 Python B] 数位排序
  • 4. 【5.15】P10901 [蓝桥杯 2024 省 C] 封闭图形个数
  • 5.【5.16】P12165 [蓝桥杯 2025 省 C/Java A] 最短距离
  • 6. 【5.17】P12186 [蓝桥杯 2025 省 Python A/研究生组] 最大数字
  • 7. 【5.18】P1012 [NOIP 1998 提高组] 拼数

正文

1. 【5.12】P1068 [NOIP 2009 普及组] 分数线划定

题目链接:https://www.luogu.com.cn/problem/P1068

【分析】
模拟排序题,复杂一点的是处理排序后的选手,按照要求输出答案。

【AC_Code】

#include <iostream>
#include <algorithm>
#include <cmath>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

struct str { int n, s; } p[5010]; int cnt;

bool cmp(str x, str y)
{
    if (x.s == y.s) return x.n < y.n;
    return x.s > y.s;
}

void solve()
{
    int n, m; cin >> n >> m;
    for (int i = 0; i < n; i ++) { cin >> p[i].n >> p[i].s; }
    sort(p, p + n, cmp);
    int S = floor(m * 1.5);
    int score_line = p[S-1].s;  // 分数线是第S个人的分数
    for (int i = 0; i < n; i ++)
    {
        if (p[i].s >= score_line) cnt ++; else break;
    }
    cout << score_line << ' ' << cnt << '\n';
    for (int i = 0; i < cnt; i ++) cout << p[i].n << ' ' << p[i].s << '\n';
}

int main()
{
    IOS int _ = 1;   // cin >> _;
    while (_ --) solve();
    
    return 0;
}

2. 【5.13】P5143 攀爬者

题目链接:https://www.luogu.com.cn/problem/P5143

【分析】

简单模拟排序题,这类题往往需要写一个结构体数组和一个比较函数,剩下的只需按题意模拟即可。

【AC_Code】

#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fix(x) setprecision(x) << fixed

using namespace std;

struct str{ int x, y, z; } s[50010]; double ans;

bool cmp(str a, str b) { return a.z < b.z; }

void solve()
{
    int n; cin >> n;
	for (int i = 0; i < n; i ++) cin >> s[i].x >> s[i].y >> s[i].z;
	sort(s, s + n, cmp);
	for (int i = 0; i < n - 1; i ++)
	{
		ans += sqrt(pow(s[i].x - s[i + 1].x, 2) + pow(s[i].y - s[i + 1].y, 2) + pow(s[i].z - s[i + 1].z, 2));
	}
	cout << fix(3) << ans << '\n';
}

int main()
{
    IOS int _ = 1;   // cin >> _;
    while (_ --) solve();
    
    return 0;
}

3. 【5.14】P12366 [蓝桥杯 2022 省 Python B] 数位排序

题目链接:https://www.luogu.com.cn/problem/P12366

【分析】
无需用到结构体。

【AC_Code】

#include <iostream>
#include <algorithm>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 1e6 + 10; int a[N], ans;

int getSum(int num)
{
	int sum = 0;
	while (num) { sum += num % 10; num /= 10; }
	return sum;
}

bool cmp(int a, int b)
{
	if (getSum(a) < getSum(b)) return true;
	if (getSum(a) == getSum(b) && a < b) return true;
	return false;
}

void solve()
{
    int n, m; cin >> n >> m;
    for (int i = 1; i <= n; i ++) { a[i] = i; }
    sort(a + 1, a + 1 + n, cmp);
	cout << a[m] << '\n';
}

int main()
{
    IOS int _ = 1;   // cin >> _;
    while (_ --) solve();
    
    return 0;
}

4. 【5.15】P10901 [蓝桥杯 2024 省 C] 封闭图形个数

题目链接:https://www.luogu.com.cn/problem/P10901

【分析】
构建一个封闭图形个数数组,发现下标刚好是要处理的单个数字,后面就很好写了。

【AC_Code】

#include <iostream>
#include <algorithm>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 2e5 + 10; int a[N], num[] = { 1, 0, 0, 0, 1, 0, 1, 0, 2, 1 };

int cnt(int NUM)
{
	int CNT = 0;
	while (NUM) { CNT += num[NUM % 10]; NUM /= 10; }
	return CNT;
}

bool cmp(int a, int b)
{
	if (cnt(a) < cnt(b)) return true;
	if (cnt(a) == cnt(b) && a < b) return true;
	return false;
}

void solve()
{
    int n; cin >> n; for (int i = 0; i < n; i ++) cin >> a[i];
    sort(a, a + n, cmp);
    for (int i = 0; i < n; i ++) cout << a[i] << " \n"[i == n - 1];
}

int main()
{
    IOS int _ = 1;   // cin >> _;
    while (_ --) solve();
    
    return 0;
}

5.【5.16】P12165 [蓝桥杯 2025 省 C/Java A] 最短距离

题目链接:https://www.luogu.com.cn/problem/P12165

【分析】
考察最朴素的贪心,可以用数学归纳法证明,比较高大上,这里不再赘述,可自行AI,最简单实用的可以通过举反例证明其合理性。

【AC_Code】

#include <iostream>
#include <algorithm>
#include <cmath>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;

const int N = 5e4 + 10; int a[N], b[N]; ll ans;

void solve()
{
    int n; cin >> n;
    for (int i = 0; i < n; i ++) cin >> a[i];
    for (int i = 0; i < n; i ++) cin >> b[i];
    sort(a, a + n); sort(b, b + n);
    for (int i = 0; i < n; i ++) ans += abs(a[i] - b[i]);
    cout << ans << '\n';
}

int main()
{
    IOS int _ = 1;   // cin >> _;
    while (_ --) solve();
    
    return 0;
}

6. 【5.17】P12186 [蓝桥杯 2025 省 Python A/研究生组] 最大数字

题目链接:https://www.luogu.com.cn/problem/P12186

【分析】
这题还没理解,参考题解代码。

【AC_Code】

#include <bits/stdc++.h>
using namespace std;
using ull = int;

// 表示大整数的结构体,使用向量存储每一位数字
struct BigInt {
    vector<ull> digits;
};

// 初始化大整数为 0
void initBigInt(BigInt& num) {
    num.digits = {0};
}

// 将大整数乘以 2
void mult2(BigInt& num) {
    ull carry = 0;
    for (int i = 0; i < num.digits.size(); ++i) {
        ull product = num.digits[i] * 2 + carry;
        num.digits[i] = product % 10;
        carry = product / 10;
    }
    if (carry != 0) {
        num.digits.push_back(carry);
    }
}

// 将大整数加 1
void add1(BigInt& num) {
    ull carry = 1;
    for (int i = 0; i < num.digits.size() && carry > 0; ++i) {
        ull sum = num.digits[i] + carry;
        num.digits[i] = sum % 10;
        carry = sum / 10;
    }
    if (carry > 0) {
        num.digits.push_back(carry);
    }
}

// 输出大整数
void output(const BigInt& num) {
    int i = num.digits.size() - 1;
    // 跳过前导零
    while (i >= 0 && num.digits[i] == 0) {
        --i;
    }
    // 如果所有位都是零,输出 0
    if (i < 0) {
        cout << "0";
        return;
    }
    // 从高位到低位输出
    while (i >= 0) {
        cout << num.digits[i];
        --i;
    }
}

// 将数字向量转换为二进制字符串
string toBinaryString(const vector<ull>& nums) {
    string bs;
    for (ull num : nums) {
        if (num == 0) {
            bs += "0";
        } else {
            string temp;
            while (num > 0) {
                temp = (num % 2 == 0 ? "0" : "1") + temp;
                num /= 2;
            }
            bs += temp;
        }
    }
    return bs;
}

// 将二进制字符串转换为大整数
BigInt trans(const vector<ull>& nums) {
    string bs = toBinaryString(nums);
    BigInt res;
    initBigInt(res);
    for (char bit : bs) {
        mult2(res);
        if (bit == '1') {
            add1(res);
        }
    }
    return res;
}

int main() {
    ull x;
    cin >> x;
    vector<ull> nums(x);
    for (int i = 0; i < x; i++) {
        nums[i] = i + 1;
    }
    // 自定义排序
    sort(nums.begin(), nums.end(), [](ull a, ull b) {
        ull bitA = log2(a) + 1;
        ull bitB = log2(b) + 1;
        ull tempA = (a << bitB) + b;
        ull tempB = (b << bitA) + a;
        return tempA > tempB;
    });
    
    BigInt bs = trans(nums);
    output(bs);
    
    return 0;
}

7. 【5.18】P1012 [NOIP 1998 提高组] 拼数

题目链接:https://www.luogu.com.cn/problem/P1012

【分析】
这题凭感觉写的,发现自己还不会证明QAQ。

【AC_Code】

#include <iostream>
#include <algorithm>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

string s[25];

bool cmp(string a, string b) { return a + b > b + a; }

void solve()
{
	int n; cin >> n;
	for (int i = 0; i < n; i ++) cin >> s[i];
	sort(s, s + n, cmp);
	for (int i = 0; i < n; i ++) cout << s[i]; cout << '\n'; 
}

int main()
{
    IOS int _ = 1;   // cin >> _;
    while (_ --) solve();
    
    return 0;
}

结语
感谢您的阅读!期待您的一键三连!欢迎指正!

在这里插入图片描述

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

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

相关文章

Typora + PicGo + GitHub 配置图床——图片自动上传 详细教程

文章目录 一、创建 GitHub 仓库二、添加私人令牌三、下载 PicGo四、配置 PicGo五、测试 一、创建 GitHub 仓库 进入 Github 官网 注册一个属于自己的账号&#xff0c;点击创建仓库。 2. 创建自己的新仓库。仓库设置为公开&#xff0c;方便上传图片&#xff08;你设置私有也可以…

QT+Visual Studio 配置开发环境教程

一、QT架构 Qt Creator 是一个轻量级、跨平台的 IDE&#xff0c;专为 Qt 开发量身打造&#xff0c;内置对 qmake/CMake 的深度支持、Kits 配置管理、原生 QML 调试器以及较低的资源占用维基百科。 而在 Windows 环境下&#xff0c;Visual Studio 配合 Qt VS Tools 扩展则可将 Q…

缺乏经验的 PCB 过孔建模方法

您是一名背板设计人员,被指派设计一种新的高速、多千兆位串行链路架构,从多个线卡到背板上的多个交换矩阵交换卡。这些链路必须在第一天以 6GB/s 的速度运行,并且为 10GB/s (IEEE 802.3KR) 做好产品演进的准备。时间表很紧,您需要提出一个背板架构,以允许程序的其余部分…

【漫话机器学习系列】265.普拉托变换的相关问题(Issues With Platt Scaling)

Platt Scaling 的相关问题详解 | 模型校准中的隐患分析 在机器学习模型中&#xff0c;模型预测的“置信度”并不一定等于真实的概率。为了提高模型预测结果的可解释性和实用性&#xff0c;我们通常会使用一种后处理的概率校准方法——Platt Scaling&#xff08;普拉托变换&…

【Linux高级全栈开发】2.2.1 Linux服务器百万并发实现2.2.2 Posix API与网络协议栈

【Linux高级全栈开发】2.2.1 Linux服务器百万并发实现2.2.2 Posix API与网络协议栈 高性能网络学习目录 基础内容&#xff08;两周完成&#xff09;&#xff1a; 2.1网络编程 2.1.1多路复用select/poll/epoll2.1.2事件驱动reactor2.1.3http服务器的实现 2.2网络原理 百万并发…

LlamaIndex

1、大语言模型开发框架的价值是什么? SDK:Software Development Kit,它是一组软件工具和资源的集合,旨在帮助开发者创建、测试、部署和维护应用程序或软件。 所有开发框架(SDK)的核心价值,都是降低开发、维护成本。 大语言模型开发框架的价值,是让开发者可以更方便地…

springboot使用xdoc-report包导出word

背景&#xff1a;项目需要使用xdoc-report.jar根据设置好的word模版&#xff0c;自动填入数据 导出word 框架使用 我的需求是我做一个模板然后往里面填充内容就导出我想要的word文件&#xff0c;问了下chatgpt还有百度&#xff0c;最后选用了xdocreport这个框架&#xff0c;主…

重拾GMP

目录 GMP总结 线程协程三家对比GMP调度模型 mgp过一遍流程 g 一个G的生命周期 mpschedt全局队列g0视角看看G的调度流程 四大调度类型 主动调度被动调度正常调度抢占调度 宏观的调度流程上面流程的具体细节 schedule()findRunnable()execute()gosched_m()park_m()与ready()goe…

实验分享|基于千眼狼sCMOS科学相机的流式细胞仪细胞核成像实验

实验背景 流式细胞仪与微流控技术&#xff0c;为细胞及细胞核成像提供新的路径。传统流式细胞仪在细胞核成像检测方面存在检测通量低&#xff0c;荧光信号微弱等局限&#xff0c;故某光学重点实验室开发一种基于高灵敏度sCMOS科学相机并集成在自组荧光显微镜的微流控细胞核成像…

【Linux笔记】——线程池项目与线程安全单例模式

&#x1f525;个人主页&#x1f525;&#xff1a;孤寂大仙V &#x1f308;收录专栏&#x1f308;&#xff1a;Linux &#x1f339;往期回顾&#x1f339;&#xff1a; 【Linux笔记】——简单实习一个日志项目 &#x1f516;流水不争&#xff0c;争的是滔滔不息 一、线程池设计二…

ZooKeeper 原理解析及优劣比较

大家好&#xff0c;这里是架构资源栈&#xff01;点击上方关注&#xff0c;添加“星标”&#xff0c;一起学习大厂前沿架构&#xff01; 引言 在分布式系统中&#xff0c;服务注册、配置管理、分布式锁、选举等场景都需要一个高可用、一致性强的协调服务。Apache ZooKeeper 凭…

是德科技 | 单通道448G未来之路:PAM4? PAM6? PAM8?

内容来源&#xff1a;是德科技 随着数据中心规模的不断扩大以及AI大模型等技术的兴起&#xff0c;市场对高速、大容量数据传输的需求日益增长。例如&#xff0c;AI训练集群中GPU等设备之间的互联需要更高的传输速率来提升效率。在技术升级方面&#xff0c;SerDes技术的不断进步…

OceanBase 开发者大会,拥抱 Data*AI 战略,构建 AI 数据底座

5 月 17 号以“当 SQL 遇见 AI”为主题的 OceanBase 开发者大会在广州举行&#xff0c;因为行程的原因未能现场参会&#xff0c;仍然通过视频直播观看了全部的演讲。总体来说&#xff0c;这届大会既有对未来数据库演进方向的展望&#xff0c;也有 OceanBase 新产品的发布&#…

STM32IIC协议基础及Cube配置

STM32IIC协议基础及Cube配置 一&#xff0c;IC协议简介1&#xff0c;核心特点2&#xff0c;应用场景 二&#xff0c;IC协议基础概念1&#xff0c;总线结构2&#xff0c;主从架构3&#xff0c;设备寻址4&#xff0c;起始和停止条件5&#xff0c;数据传输6&#xff0c;应答机制 三…

CNN vs ViT:图像世界的范式演进

一、图像建模&#xff0c;是不是也可以“大一统” 在前文中我们提到&#xff0c;多模态大模型打破“只能处理文字”的限制。 在 NLP 世界里&#xff0c;Transformer 已经证明自己是理解语言的王者。那么在图像世界&#xff0c;我们是否也能有一种“通用架构”&#xff0c;让模…

cocos creator使用jenkins打包微信小游戏,自动上传资源到cdn,windows版运行jenkins

cocos 版本2.4.11 在windows上jenkins的具体配置和部署&#xff0c;可参考上一篇文章cocos creator使用jenkins打包流程&#xff0c;打包webmobile_jenkins打包,发布,部署cocoscreator-CSDN博客 特别注意&#xff0c;windows上运行jenkins需要关闭windows自己的jenkins服务&a…

定时器的两种实现方式

1、基于优先级队列/堆 队列是先进先出&#xff0c;优先级队列是优先级越高就存放在队列之前&#xff0c;我们可以将过期时间越早设置为优先级越高&#xff0c;那么临近过期时间的任务就会在队列前面&#xff0c;距离过期时间越晚的任务就在队列后面。 可以分配一个线程&#…

[Java实战]Spring Boot整合MinIO:分布式文件存储与管理实战(三十)

[Java实战]Spring Boot整合MinIO&#xff1a;分布式文件存储与管理实战&#xff08;三十&#xff09; 一、MinIO简介与核心原理 MinIO 是一款高性能、开源的分布式对象存储系统&#xff0c;兼容 Amazon S3 API&#xff0c;适用于存储图片、视频、日志等非结构化数据。其核心特…

AI在人力资源领域的应用:把握时代浪潮

借鉴历史经验&#xff0c;引领技术变革 历史总是呈现出惊人的相似性。十年前&#xff0c;众多企业未能及时洞察移动技术与社交技术的潜在价值&#xff0c;迟迟没有将这些创新引入职场环境。随着时间推移&#xff0c;这些组织才意识到BYOD&#xff08;自带设备办公&#xff09;…

vr制作公司提供什么服务?

随着科技的迅猛进步&#xff0c;虚拟现实&#xff08;Virtual Reality&#xff0c;简称VR&#xff09;技术已经悄然渗透到我们的日常生活与工作中&#xff0c;成为推动数字化转型的重要力量。VR制作公司&#xff0c;作为前沿领域的探索者和实践者&#xff0c;以专业的技术和创新…