xtu oj 聚会

devtools/2024/11/14 7:19:14/
cle class="baidu_pl">
cle_content" class="article_content clearfix">
content_views" class="markdown_views prism-tomorrow-night">cap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);">

class="toc">

文章目录

  • 回顾
  • 代码
  • 思路

回顾

  • A+B III
  • 问题 H: 三角数
  • 问题 G: 3个数
  • 等式 数组下标查询࿰c;降低时间复杂度
  • 1405 问题 E: 世界杯
  • xtu 数码串
  • xtu oj 神经网络
  • xtu oj 1167 逆序数(大数据)
  • xtu oj 原根
  • xtu oj 不定方程的正整数解
  • xtu oj 最多的可变换字符串
  • xtu oj String I
  • xtu oj 字母序列
  • xtu oj 分段
  • xtu oj 完全平方数II
  • xtu oj 连接字符串
  • xtu oj 2021
  • xtu oj 数字
  • xtu oj 删除

代码

<code class="prism language-c">class="token macro property">class="token directive-hash">#class="token directive keyword">includeclass="token string"><stdio.h>
class="token macro property">class="token directive-hash">#class="token directive keyword">define class="token macro-name">N class="token expression">class="token number">10010
class="token keyword">int aclass="token punctuation">[Nclass="token punctuation">]class="token punctuation">;
class="token keyword">void class="token function">sortclass="token punctuation">(class="token keyword">int qclass="token punctuation">[class="token punctuation">]class="token punctuation">,class="token keyword">int lclass="token punctuation">,class="token keyword">int rclass="token punctuation">)class="token punctuation">{class="token comment">//快速排序模板class="token keyword">ifclass="token punctuation">(lclass="token operator">>=rclass="token punctuation">)class="token punctuation">{class="token keyword">returnclass="token punctuation">;class="token punctuation">}class="token keyword">int iclass="token operator">=lclass="token operator">-class="token number">1class="token punctuation">,jclass="token operator">=rclass="token operator">+class="token number">1class="token punctuation">,xclass="token operator">=qclass="token punctuation">[class="token punctuation">(lclass="token operator">+rclass="token punctuation">)class="token operator">/class="token number">2class="token punctuation">]class="token punctuation">;class="token keyword">whileclass="token punctuation">(iclass="token operator"><jclass="token punctuation">)class="token punctuation">{class="token keyword">doclass="token punctuation">{iclass="token operator">++class="token punctuation">;class="token punctuation">}class="token keyword">whileclass="token punctuation">(qclass="token punctuation">[iclass="token punctuation">]class="token operator"><xclass="token punctuation">)class="token punctuation">;class="token keyword">doclass="token punctuation">{jclass="token operator">--class="token punctuation">;class="token punctuation">}class="token keyword">whileclass="token punctuation">(qclass="token punctuation">[jclass="token punctuation">]class="token operator">>xclass="token punctuation">)class="token punctuation">;class="token keyword">ifclass="token punctuation">(iclass="token operator"><jclass="token punctuation">)class="token punctuation">{class="token keyword">int tempclass="token operator">=qclass="token punctuation">[iclass="token punctuation">]class="token punctuation">;qclass="token punctuation">[iclass="token punctuation">]class="token operator">=qclass="token punctuation">[jclass="token punctuation">]class="token punctuation">;qclass="token punctuation">[jclass="token punctuation">]class="token operator">=tempclass="token punctuation">;class="token punctuation">}class="token punctuation">}class="token function">sortclass="token punctuation">(qclass="token punctuation">,lclass="token punctuation">,jclass="token punctuation">)class="token punctuation">;class="token function">sortclass="token punctuation">(qclass="token punctuation">,jclass="token operator">+class="token number">1class="token punctuation">,rclass="token punctuation">)class="token punctuation">;
class="token punctuation">}
class="token keyword">int class="token function">mainclass="token punctuation">(class="token punctuation">)class="token punctuation">{class="token keyword">int tclass="token punctuation">;class="token function">scanfclass="token punctuation">(class="token string">"%d"class="token punctuation">,class="token operator">&tclass="token punctuation">)class="token punctuation">;class="token keyword">whileclass="token punctuation">(tclass="token operator">--class="token punctuation">)class="token punctuation">{class="token keyword">int nclass="token punctuation">;class="token function">scanfclass="token punctuation">(class="token string">"%d"class="token punctuation">,class="token operator">&nclass="token punctuation">)class="token punctuation">;class="token comment">//所有朋友的个数class="token keyword">forclass="token punctuation">(class="token keyword">int iclass="token operator">=class="token number">0class="token punctuation">;iclass="token operator"><nclass="token punctuation">;iclass="token operator">++class="token punctuation">)class="token punctuation">{class="token function">scanfclass="token punctuation">(class="token string">"%d"class="token punctuation">,class="token operator">&aclass="token punctuation">[iclass="token punctuation">]class="token punctuation">)class="token punctuation">;class="token punctuation">}class="token function">sortclass="token punctuation">(aclass="token punctuation">,class="token number">0class="token punctuation">,nclass="token operator">-class="token number">1class="token punctuation">)class="token punctuation">;class="token keyword">int sumclass="token operator">=class="token number">1class="token punctuation">;class="token comment">//现在有多少人来聚会了class="token keyword">int ansclass="token operator">=class="token number">0class="token punctuation">;class="token comment">//会来多少朋友class="token keyword">forclass="token punctuation">(class="token keyword">int iclass="token operator">=class="token number">0class="token punctuation">;iclass="token operator"><nclass="token punctuation">;iclass="token operator">++class="token punctuation">)class="token punctuation">{class="token keyword">ifclass="token punctuation">(aclass="token punctuation">[iclass="token punctuation">]class="token operator"><=sumclass="token punctuation">)class="token punctuation">{class="token comment">//至少来 sum 个朋友࿰c;i 这个朋友就会来ansclass="token operator">++class="token punctuation">;class="token comment">//多一个朋友来sumclass="token operator">++class="token punctuation">;class="token comment">//聚会的总人数多一个class="token punctuation">}class="token punctuation">}class="token function">printfclass="token punctuation">(class="token string">"%d\n"class="token punctuation">,ansclass="token punctuation">)class="token punctuation">;class="token punctuation">}class="token keyword">return class="token number">0class="token punctuation">;
class="token punctuation">}
code>

思路

<code class="prism language-cpp">class="token macro property">class="token directive-hash">#class="token directive keyword">includeclass="token string"><stdio.h>
class="token macro property">class="token directive-hash">#class="token directive keyword">define class="token macro-name">N class="token expression">class="token number">10010
class="token keyword">int aclass="token punctuation">[Nclass="token punctuation">]class="token punctuation">;
class="token keyword">int class="token function">mainclass="token punctuation">(class="token punctuation">)class="token punctuation">{class="token keyword">int tclass="token punctuation">;class="token function">scanfclass="token punctuation">(class="token string">"%d"class="token punctuation">,class="token operator">&tclass="token punctuation">)class="token punctuation">;class="token keyword">whileclass="token punctuation">(tclass="token operator">--class="token punctuation">)class="token punctuation">{class="token keyword">int nclass="token punctuation">;class="token function">scanfclass="token punctuation">(class="token string">"%d"class="token punctuation">,class="token operator">&nclass="token punctuation">)class="token punctuation">;class="token comment">//所有朋友的个数class="token keyword">forclass="token punctuation">(class="token keyword">int iclass="token operator">=class="token number">0class="token punctuation">;iclass="token operator"><nclass="token punctuation">;iclass="token operator">++class="token punctuation">)class="token punctuation">{class="token function">scanfclass="token punctuation">(class="token string">"%d"class="token punctuation">,class="token operator">&aclass="token punctuation">[iclass="token punctuation">]class="token punctuation">)class="token punctuation">;class="token punctuation">}class="token keyword">int sumclass="token operator">=class="token number">1class="token punctuation">;class="token comment">//现在有多少人来聚会了class="token keyword">int ansclass="token operator">=class="token number">0class="token punctuation">;class="token comment">//会来多少朋友class="token keyword">forclass="token punctuation">(class="token keyword">int iclass="token operator">=class="token number">0class="token punctuation">;iclass="token operator"><nclass="token punctuation">;iclass="token operator">++class="token punctuation">)class="token punctuation">{class="token keyword">ifclass="token punctuation">(aclass="token punctuation">[iclass="token punctuation">]class="token operator"><=sumclass="token punctuation">)class="token punctuation">{class="token comment">//至少来 sum 个朋友࿰c;i 这个朋友就会来ansclass="token operator">++class="token punctuation">;class="token comment">//多一个朋友来sumclass="token operator">++class="token punctuation">;class="token comment">//聚会的总人数多一个class="token punctuation">}class="token punctuation">}class="token function">printfclass="token punctuation">(class="token string">"%d\n"class="token punctuation">,ansclass="token punctuation">)class="token punctuation">;class="token punctuation">}class="token keyword">return class="token number">0class="token punctuation">;
class="token punctuation">}
code>

为啥直接 <code>WAcode> 了࿰c;样例也能过࿰c;然后也不会出现需要用 <code>long longcode> 的情况。嗷嗷࿰c;不是按照顺序排的。哈哈哈。贪心地做࿰c;就是让那种要求低的朋友排在前面࿰c;这样来聚会的人就会尽可能多。

排序一下就过了࿰c;幸福。

但是我这里写了一个快速排序的模板࿰c;有没有啥简单一点的办法来排序呢?要是找到了更好的办法会更新在评论区。


http://www.ppmy.cn/devtools/133858.html

相关文章

移动硬盘需要格式化才能打开?详解原因与数据恢复方案

描述移动硬盘需要格式化才能打开 当我们尝试访问移动硬盘时&#xff0c;有时会遇到系统提示“需要格式化才能打开”的情况。这种提示通常意味着硬盘上的文件系统已损坏或无法被系统正常识别。一旦遇到这种情况&#xff0c;很多用户会感到焦虑&#xff0c;因为硬盘中可能存储了…

Logback 日志介绍及与Spring Boot 的整合 【保姆级教程】

Logback介绍 Logback是SpringBoot框架的默认的日志&#xff0c;内容如下图所示&#xff1a; Log4J 的创始人 Ceki Glc 和另一位 Log4J 贡献者 Sbastien Pennec 设计了 ​​logback。他们设计的 Logback 具有快速和通用的特性&#xff0c;可以在不同的环境下工作。 Logback 由…

11.9.2024刷华为

文章目录 HJ31 单词倒排HJ32 密码提取语法知识记录 傻逼OD题目又不全又要收费&#xff0c;看毛线&#xff0c;莫名奇妙 HW这叼机构别搁这儿害人得不得&#xff1f; 我觉得我刷完原来的题目 过一遍华为机考的ED卷出处&#xff0c;就行了 HJ31 单词倒排 游戏本做过了好像 HJ3…

MySQL常用订单表复杂查询15例

MySQL常用订单表复杂查询15例 在电子商务平台中&#xff0c;我们通常需要处理大量的数据查询任务。本文将介绍十五个复杂的 MySQL 查询任务及其示例代码。需要mysql8.0.X以上环境进行测试&#xff0c;因为使用到了窗口函数。 假设我们有一个电子商务平台&#xff0c;包含以下…

当微软windows的记事本被AI加持

1985年&#xff0c;微软发布了Windows 1.0&#xff0c;推出了一款革命性的产品&#xff1a;记事本&#xff08;Notepad&#xff09;。这款软件旨在鼓励使用一种未来主义的新设备——鼠标&#xff0c;并让人们可以不依赖VI等键盘工具就能书写文本和编写代码。记事本因其简洁和高…

Github 2024-11-09Rust开源项目日报 Top10

根据Github Trendings的统计,今日(2024-11-09统计)共有10个项目上榜。根据开发语言中项目的数量,汇总情况如下: 开发语言项目数量Rust项目10CUE项目1Python项目1Polars: Rust中的DataFrame接口和OLAP查询引擎 创建周期:1354 天开发语言:Rust, Python协议类型:MIT License…

数字字符串格式化

小M在工作时遇到了一个问题&#xff0c;他需要将用户输入的不带千分位逗号的数字字符串转换为带千分位逗号的格式&#xff0c;并且保留小数部分。小M还发现&#xff0c;有时候输入的数字字符串前面会有无用的 0&#xff0c;这些也需要精简掉。请你帮助小M编写程序&#xff0c;完…

Prometheus 和 Grafana 以进行服务器监控

部署 Prometheus 和 Grafana 以进行服务器监控是一项非常实用的任务&#xff0c;它们可以帮助你收集和可视化系统性能数据。以下是一个详细的步骤指南&#xff0c;帮助你在 Linux 服务器上部署 Prometheus 和 Grafana&#xff0c;进行监控配置。 1. 安装 Prometheus 1.1 下载…