![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
刷题宝典
文章平均质量分 75
艺千秋录
时间是一位伟大的作者,它必将写出一个最完美的答案!
展开
-
POJ- 3468(线段树)
题目描述代码题解#include<map>#include<algorithm>#include<cstdio>#include<cstring>#include<iostream>#include<queue>#include<set>#include<vector>#include<numeric>#include<string>using namespace原创 2020-09-28 21:40:36 · 96 阅读 · 0 评论 -
HDU--1754(树状数组)
传送门题目描述:代码题解#include<map>#include<algorithm>#include<cstdio>#include<cstring>#include<iostream>#include<queue>#include<set>#include<vector>#include<numeric>#include<string>using name原创 2020-09-28 20:04:25 · 253 阅读 · 0 评论 -
HDU-1495:非常可乐(BFS)
传送门题目描述Problem Description大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为。因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享这一瓶可乐,而且一定要喝的和seeyou一样多。但seeyou的手中只有两个杯子,它们的容量分别是N 毫升和M 毫升 可乐的体积为S (S<101)毫升 (正好装满一瓶) ,它们三个之间可以相互倒可乐 (都是没有刻度的,且 S==N+M,101>S>0,N>0,M>0) 。聪明的ACMER你们说他们能平原创 2020-09-25 16:30:03 · 81 阅读 · 0 评论 -
牛客:字符串(动态规划)
题目描述代码实现#include<map>#include<algorithm>#include<cstdio>#include<cstring>#include<iostream>#include<queue>#include<set>#include<vector>#include<numeric>using namespace std;const long long原创 2020-09-21 19:20:34 · 112 阅读 · 0 评论 -
牛客--DDos(深度优先搜索)
题目描述代码实现#include<map>#include<algorithm>#include<cstdio>#include<cstring>#include<iostream>#include<queue>#include<set>#include<vector>#include<numeric>using namespace std;struct node{ ve原创 2020-09-21 17:11:30 · 100 阅读 · 0 评论 -
牛客Bits竞赛
传送门题目描述:代码实现#include<map>#include<algorithm>#include<cstdio>#include<cstring>#include<iostream>#include<queue>#include<set>#include<vector>#include<numeric>using namespace std;int n, t[5],原创 2020-09-21 17:07:11 · 95 阅读 · 0 评论 -
牛客:博弈论
代码如下:#include<map>#include<algorithm>#include<cstdio>#include<cstring>#include<iostream>#include<queue>#include<set>#include<vector>#include<numeric>using namespace std;#define ll long long.原创 2020-09-19 23:29:58 · 155 阅读 · 0 评论 -
POJ-6187:Destroy Walls(最大生成树)
传送门Problem DescriptionLong times ago, there are beautiful historic walls in the city. These walls divide the city into many parts of area.Since it was not convenient, the new king wants to destroy some of these walls, so he can arrive anywhere from his原创 2020-09-12 14:43:57 · 80 阅读 · 0 评论 -
力扣题解:马戏团人塔(排序+二分查找)
传送门题目描述有个马戏团正在设计叠罗汉的表演节目,一个人要站在另一人的肩膀上。出于实际和美观的考虑,在上面的人要比下面的人矮一点且轻一点。已知马戏团每个人的身高和体重,请编写代码计算叠罗汉最多能叠几个人。示例:输入:height = [65,70,56,75,60,68] weight = [100,150,90,190,95,110]输出:6解释:从上往下数,叠罗汉最多能叠 6 层:(56,90), (60,95), (65,100), (68,110), (70,150), (75,190)原创 2020-08-18 22:56:50 · 614 阅读 · 1 评论 -
力扣题解1235. 规划兼职工作(动态规划)
传送门题目描述你打算利用空闲时间来做兼职工作赚些零花钱。这里有 n 份兼职工作,每份工作预计从 startTime[i] 开始到 endTime[i] 结束,报酬为 profit[i]。给你一份兼职工作表,包含开始时间 startTime,结束时间 endTime 和预计报酬 profit 三个数组,请你计算并返回可以获得的最大报酬。注意,时间上出现重叠的 2 份工作不能同时进行。如果你选择的工作在时间 X 结束,那么你可以立刻进行在时间 X 开始的下一份工作。示例 1:输入:startTim原创 2020-08-15 17:54:26 · 608 阅读 · 0 评论 -
力扣题解:二叉树的层序遍历(BFS)
传送门/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: vector<vector<int>原创 2020-08-10 16:52:59 · 202 阅读 · 0 评论 -
力扣题解:853车队(排序)
传送门题目描述N 辆车沿着一条车道驶向位于 target 英里之外的共同目的地。每辆车 i 以恒定的速度 speed[i] (英里/小时),从初始位置 position[i] (英里) 沿车道驶向目的地。一辆车永远不会超过前面的另一辆车,但它可以追上去,并与前车以相同的速度紧接着行驶。此时,我们会忽略这两辆车之间的距离,也就是说,它们被假定处于相同的位置。车队 是一些由行驶在相同位置、具有相同速度的车组成的非空集合。注意,一辆车也可以是一个车队。即便一辆车在目的地才赶上了一个车队,它们仍然原创 2020-08-10 15:16:43 · 248 阅读 · 0 评论 -
力扣题解:区间和的个数
传送门题目描述给定一个整数数组 nums,返回区间和在 [lower, upper] 之间的个数,包含 lower 和 upper。 区间和 S(i,j) 表示在 nums 中,位置从 i 到 j 的元素之和,包含 i 和 j (i ≤ j)。说明:最直观的算法复杂度是 O(n2) ,请在此基础上优化你的算法。示例:输入: nums = [-2,5,-1], lower = -2, upper = 2,输出: 3解释: 3个区间分别是:[0,0], [2,2], [0,2],它们原创 2020-08-07 17:43:02 · 227 阅读 · 0 评论 -
力扣题解:重构字符串
传送门题目描述给定一个字符串S,检查是否能重新排布其中的字母,使得两相邻的字符不同。若可行,输出任意可行的结果。若不可行,返回空字符串。示例 1:输入: S = “aab”输出: “aba”示例 2:输入: S = “aaab”输出: “”注意:S 只包含小写字母并且长度在[1, 500]区间内。class Solution {public: string reorganizeString(string S) { vector<int&原创 2020-08-07 11:04:08 · 192 阅读 · 0 评论 -
力扣题解:盛最多水的容器
传送门class Solution {public: int maxArea(vector<int>& height) { int maxvol = 0; int left = 0,right = height.size() - 1; while(left < right) { int hei = 0; if(height[left]<height[r原创 2020-08-03 22:32:14 · 134 阅读 · 0 评论 -
力扣329. 矩阵中的最长递增路径
传送门题目描述给定一个整数矩阵,找出最长递增路径的长度。 对于每个单元格,你可以往上,下,左,右四个方向移动。你不能在对角线方向上移动或移动到边界外(即不允许环绕)。示例 1:输入: nums = [ [9,9,4], [6,6,8], [2,1,1] ]输出: 4解释: 最长递增路径为[1, 2, 6, 9]。示例 2:输入: nums = [ [3,4,5], [3,2,6], [2,2,1] ]输出: 4解释: 最长递增路径是 [3, 4,原创 2020-07-26 18:22:24 · 192 阅读 · 0 评论 -
HDU-3903:Trigonometric Function(三角函数与无理数)
传送门Problem DescriptionGive you a triangle ABC. Get more information in the picture below.Now, give you 6 integers a, b, c, n, m and k. a, b and c are triangle ABC`s three edges. Can you judge whether the result of the following fraction is rational num原创 2020-07-18 22:47:07 · 220 阅读 · 0 评论 -
力扣题解:将二叉树变平衡
传送门题目描述代码实现/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: vector<int>原创 2020-07-12 16:04:21 · 201 阅读 · 0 评论 -
力扣题解:从二叉搜索树到更大和树
传送门题目描述:代码实现/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: TreeNode* bstTo原创 2020-07-12 15:22:45 · 166 阅读 · 0 评论 -
poj-3737:UmBasketella(三分与数学)
传送门DescriptionIn recent days, people always design new things with multifunction.For instance, you can not only use cell phone to call your friends,but you can also use your cell phone take photographs or listen toMP3. Another example is the combinat原创 2020-07-04 10:14:31 · 196 阅读 · 0 评论 -
poj-1064:Cable master(二分查找,精度控制)
DescriptionInhabitants of the Wonderland have decided to hold a regionalprogramming contest. The Judging Committee has volunteered and haspromised to organize the most honest contest ever. It was decided toconnect computers for the contestants using a原创 2020-07-03 17:21:23 · 153 阅读 · 0 评论 -
HDU-5167:Fibonacci(C++详细代码实现)
传送门Problem DescriptionFollowing is the recursive definition of Fibonacci sequence:Now we need to check whether a number can be expressed as the productof numbers in the Fibonacci sequence.InputThere is a number T shows there are T test cases belo原创 2020-06-27 20:39:14 · 137 阅读 · 0 评论 -
POJ-2632:Crashing Robots(C++实现详细代码)
传送门DescriptionIn a modernized warehouse, robots are used to fetch the goods. Carefulplanning is needed to ensure that the robots reach their destinationswithout crashing into each other. Of course, all warehouses arerectangular, and all robots occupy原创 2020-06-26 20:13:01 · 245 阅读 · 0 评论 -
POJ-2251:Dungeon Master(C++详细代码实现)
DescriptionYou are trapped in a 3D dungeon and need to find the quickest way out!The dungeon is composed of unit cubes which may or may not be filledwith rock. It takes one minute to move one unit north, south, east,west, up or down. You cannot move d原创 2020-06-26 11:35:10 · 493 阅读 · 0 评论 -
HDU-2717:Catch That Cow
传送门Problem DescriptionFarmer John has been informed of the location of a fugitive cow andwants to catch her immediately. He starts at a point N (0 ≤ N ≤100,000) on a number line and the cow is at a point K (0 ≤ K ≤100,000) on the same number line. Fa原创 2020-06-25 23:35:05 · 138 阅读 · 0 评论 -
HDU-1789:Doing Homework again
Problem DescriptionIgnatius has just come back school from the 30th ACM/ICPC. Now he hasa lot of homework to do. Every teacher gives him a deadline of handingin the homework. If Ignatius hands in the homework after the deadline,the teacher will reduce原创 2020-06-25 21:20:39 · 176 阅读 · 0 评论 -
剪绳子:(数学+动态规划+贪心)
原题链接题目描述:方法一:利用数学公式推导根据题意,任意一段长为n绳子都可以细分为a段(n=n1+n2+n3+...+nan=n_1+n_2+n_3+...+n_an=n1+n2+n3+...+na);要使S=n1×n2×n3×...×naS=n_1\times n_2\times n_3\times...\times n_aS=n1×n2×n3×...×na值最大,由...原创 2020-05-13 13:39:06 · 383 阅读 · 0 评论 -
算法中的博弈论:电话游戏
原题链接题目描述A telephone number is a sequence of exactly 1111 digits such that its first digit is 8.Vasya and Petya are playing a game. Initially they have a string ss of length nn (nn is odd) consisting of digits. Vasya makes the first move, then players al原创 2020-05-10 20:23:06 · 289 阅读 · 0 评论 -
算法中的博弈论——石头游戏
原题链接石头游戏题目描述亚历克斯和李用几堆石子在做游戏。偶数堆石子排成一行,每堆都有正整数颗石子 piles[i] 。游戏以谁手中的石子最多来决出胜负。石子的总数是奇数,所以没有平局。亚历克斯和李轮流进行,亚历克斯先开始。 每回合,玩家从行的开始或结束处取走整堆石头。 这种情况一直持续到没有更多的石子堆为止,此时手中石子最多的玩家获胜。假设亚历克斯和李都发挥出最佳水平,当亚历克斯赢得比赛时返回 true ,当李赢得比赛时返回 false 。示例:输入:[5,3,4,5]输出:true原创 2020-05-09 11:17:11 · 741 阅读 · 0 评论 -
算法题解:POJ-1852蚂蚁军队
原题链接DescriptionAn army of ants walk on a horizontal pole of length l cm, each with aconstant speed of 1 cm/s. When a walking ant reaches an end of thepole, it immediatelly falls off it. When two ...原创 2020-05-04 15:16:12 · 515 阅读 · 0 评论 -
POJ-2676 数独:(详细题解)深度优先搜索
原题链接DescriptionSudoku is a very simple task. A square table with 9 rows and 9 columns is divided to 9 smaller squares 3x3 as shown on the Figure. In some of the cells are written decimal digits from...原创 2020-05-03 12:07:40 · 1017 阅读 · 0 评论 -
最长上升子序列:详细题解+动画演示(动态规划和二分查找)
原题链接题目描述:给定一个无序的整数数组,找到其中最长上升子序列的长度。示例:输入:[10,9,2,5,3,7,101,18]输出:4解释: 最长的上升子序列是 [2,3,7,101],它的长度是 4。说明:可能会有多种最长上升子序列的组合,你只需要输出对应的长度即可。你算法的时间复杂度应该为 O(n2) 。进阶: 你能将算法的时间复杂度降低到O(n logn)吗?...原创 2020-05-02 13:11:31 · 689 阅读 · 3 评论 -
POJ-1190生日蛋糕(详细题解)深度优先搜索
一、> 如果搭建完剩余层所需的最小体积(min_v)比剩余可用体积($V-V_i,其中V_i$表示搭建底层蛋糕已经使用的体积)还要大,则说明题目所固定的体积**不够用**,此时应该减小底层固定的半径$R_i和H_i$,直到它们满足第三种情况二、> 如果搭建完剩余蛋糕层所需最大体积(max_v)比剩余可用体积($V-V_i$)还要小的话,则说用题目所固定的体积**用不完**,此时应该增大底层固定的半径$R_i和H_i$,直到它们满足第三种情况> 三、如果搭建完剩余蛋糕层所需的最小体积(min原创 2020-04-30 14:53:18 · 2897 阅读 · 0 评论 -
力扣题解:最大子序和(动态规划)
原题目链接题目描述:给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。示例:输入: [-2,1,-3,4,-1,2,1,-5,4],输出: 6解释: 连续子数组 [4,-1,2,1] 的和最大,为 6。题解思路:第一步:先定义一个int型数据记录最大子序和maxsubbarray,初始值等于数组的第一个元素(注意不能定义为0,因...原创 2020-04-29 23:32:29 · 281 阅读 · 0 评论