随笔分类 - 题解
即兴而写的题目题解
摘要:先看看代码吧,题解有空再补 A.宇宙校园跑(一)/ Cosmic Campus Run (Part I) #include <bits/stdc++.h> #ifdef LOCAL #include "algo/debug.hpp" #else #define debug(...) 42 #endi
阅读全文
摘要:预测难度 Easy:A、E Medium:C、D Hard:B、F A - 我不是签到题 代码实现 #include <bits/stdc++.h> #ifdef LOCAL #include "algo/debug.hpp" #else #define debug(...) 42 #endif i
阅读全文
摘要:预测难度 Easy:A、C Medium:E、B、F Hard:D 实际难度 Easy:A、C Medium:F、B Hard:D、E A - Debug 分析 错误存在第7行 s.length()和s.size()返回的类型为unsigned long long,当有符号型整数遇到无符号整数时类型
阅读全文
摘要:水水水~ 题目链接戳我 分析 首先根据题目条件可得式子=>\((x - 2)(y - 2) = n(2x + 2y - 4)\) 化简式子可得 \[\begin{align} (x - 2)(y - 2) = &n(2x + 2y - 4)\\ xy - 2x - 2y + 4 = &2nx + 2
阅读全文
摘要:2024-7-1 LCP 40. 心算挑战 代码实现 class Solution { public: int maxmiumScore(vector<int>& cards, int cnt) { int n = size(cards); std::sort(cards.rbegin(), car
阅读全文
摘要:剑指Offer题单及题解 题目顺序为牛客上剑指Offer专题 JZ3、数组中重复的数字 分析 可以直接对数组进行排序,通过判断首末数字大小来判断数字越界情况,注意数组为空的情况。发现 \(0 \leq nums[i] \leq n - 1\), 因此直接开一个数组判断是否有重复数字即可,返回第一个重
阅读全文
摘要:A、小红的最大价值 无聊打一下 代码实现 #include <bits/stdc++.h> #ifdef LOCAL #include "algo/debug.h" #else #define debug(...) 42 #endif int main() { std::cin.tie(nullpt
阅读全文
摘要:2024-7-1 2065. 最大化一张图中的路径价值 分析 注意观察到至多走十条边,因此直接爆搜即可。 代码实现 class Solution { public: int maximalPathQuality(vector<int>& values, vector<vector<int>>& ed
阅读全文
摘要:A - Count Takahashi 水一篇 代码实现 #include <bits/stdc++.h> #ifdef LOCAL #include "algo/debug.h" #else #define debug(...) 42 #endif int main() { std::cin.ti
阅读全文
摘要:A、小红的葫芦 水一篇 代码实现 #include <bits/stdc++.h> #ifdef LOCAL #include "algo/debug.h" #else #define debug(...) 42 #endif int main() { std::cin.tie(nullptr)->
阅读全文
摘要:E - Boomerang(动态维护树的直径 + 二分) 分析 首先考虑对于当\(t_0 + x\)时刻的传播谣言的树形图,可以发现选择这棵树直径的中点开始进行辟谣是最优的,那么只需要二分一下时间,即在二分给定的时间内开始以\(k=i\)的速度辟谣,能否在二分的时间内辟谣成功(能否跑完这课谣言树)。
阅读全文
摘要:2024-6-1 2928. 给小朋友们分糖果 I 分析 枚举所有可能的方案数即可 代码实现 class Solution { public: int distributeCandies(int n, int limit) { int ans = 0; for (int a = 0; a <= li
阅读全文
摘要:A - Once In My Life (构造) 分析 根据题目要求需要两个d,并且要保证123456789都存在,那么就可以尝试先构造出一个数保证存在123456789。 尝试以下构造方式:设n的长度为len,则可以构造出\(k*n=({\frac{123456789*10^{len + 1}}n
阅读全文
摘要:借用SDUT版《不是,哥们》镇楼 A、欢迎来到山东理工大学第十六届程序设计竞赛(我是听话的乖宝宝) 分析 分析?没有分析~ 代码实现 #include <bits/stdc++.h> int main() { std::cin.tie(nullptr)->sync_with_stdio(false)
阅读全文
摘要:A. Adjusted Average(暴力枚举+二分查找) 分析 读完题目可以发现k很小,那么考虑暴力做法的时间复杂度为\(O(C_n^k)\),对于\(k\leq3\)的其实可以直接暴力创过去,但对于\(k=4\)的情况显然不适用。那么对应\(k=4\)的情况考虑优化,可以选择将数分为两个集合,
阅读全文
摘要:2024-5-6 1463. 摘樱桃 II 代码实现 class Solution { public: int cherryPickup(vector<vector<int>>& grid) { int n = size(grid), m = size(grid[0]); std::vector f
阅读全文
摘要:E - Easy Compare-and-Set 题意 给定n个条件,如果存在一个合法序列使得这n个判断条件成立,则输出Yes和这个合法序列,否则输出No。 分析 首先可以发现对于\(w_i = 0\)的操作我们可以在处理完\(w_i = 1\)的操作之后讨论一下即可。 发现\(a_i\)和\(b_
阅读全文
摘要:D - Association of Computer Maintenance 题意 给定至多350个小于100的质数,对于所有质数之积k将它分解为两个数a和b使得a*b=k。输出最小的a+b,并对1e9+7取模 分析 首先考虑想如果想让a+b最小,即让abs(a-b)最小。根据限制条件k的因子数不
阅读全文

浙公网安备 33010602011771号