【Leetcode_easy】1046. Last Stone Weight】的更多相关文章

problem 1046. Last Stone Weight 参考 1. Leetcode_easy_1046. Last Stone Weight; 完…
题目如下: We have a collection of rocks, each rock has a positive integer weight. Each turn, we choose the two heaviest rocks and smash them together.  Suppose the stones have weights x and y with x <= y.  The result of this smash is: If x == y, both sto…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 大根堆 日期 题目地址:https://leetcode.com/problems/last-stone-weight/ 题目描述 We have a collection of rocks, each rock has a positive integer weight. Each turn, we choose the two heaviest…
1046. 最后一块石头的重量 1046. Last Stone Weight 题目描述 每日一算法2019/6/22Day 50LeetCode1046. Last Stone Weight Java 实现 and so on 参考资料 https://leetcode.com/problems/last-stone-weight/ https://leetcode-cn.com/problems/last-stone-weight/…
[题目] Description The funny stone game is coming. There are n piles of stones, numbered with 0, 1, 2, ..., n − 1. Twopersons pick stones in turn. In every turn, each person selects three piles of stones numbered i, j, k(i < j, j ≤ k and at least one s…
[算法]快速幂运算 [题解]快速幂的原理是把幂用二进制表示,从最低位a,次低位a2,次次低位(a2)2. #include<cstdio> long long quick_pow(long long a,long long b,long long c) { ; ) { )ans=(ans*a)%c; b/=; a=(a*a)%c; } return ans; } int main() { long long a,b,c; scanf("%lld%lld%lld",&…
原题链接在这里:https://leetcode.com/problems/last-stone-weight/ 题目: We have a collection of rocks, each rock has a positive integer weight. Each turn, we choose the two heaviest rocks and smash them together.  Suppose the stones have weights x and y with x…
lc57 Insert Interval 仔细分析题目,发现我们只需要处理那些与插入interval重叠的interval即可,换句话说,那些end早于插入start以及start晚于插入end的interval都可以保留.我们只需要两个指针,i&j分别保存重叠interval中最早start和最晚end即可,然后将interval [i, j]插入即可 class Solution { public int[][] insert(int[][] intervals, int[] newInte…
http://poj.org/problem?id=1740 题目大意就是,对于n堆石子,每堆若干个,两人轮流操作,每次操作分两步,第一步从某堆中去掉至少一个,第二步(可省略)把该堆剩余石子的一部分分给其它的某些堆.最后谁无子可取即输. 看了题解感觉太神了. 首先我们来分析: 当只有一堆时,先手必胜,直接一次取完即可 当有两堆时,分两种情况,一是两堆相同时,先手必输,因为无论先手怎样取,后手总有办法再次平衡两堆:而是两堆不同时,先手必胜,因为先手总有办法先平衡两堆,然后就像一的情况. 当有三堆时…
1046: [HAOI2007]上升序列 题意:给定S={a1,a2,a3,…,an}问是否存在P={ax1,ax2,ax3,…,axm},满足(x1 < x2 < … < xm)且( ax1 < ax2 < … < axm),若存在多组符合长度为m的递增子序列,则输出以序号字典序最小的:并非是数值 Sample Input 6 3 4 1 2 3 6 3 6 4 5 Sample Output Impossible 1 2 3 6 Impossible 数据范围 N&…
http://www.lydsy.com/JudgeOnline/problem.php?id=1046 一直看错题....................... 这是要求位置的字典序啊QQQAAAQQQ .. 那么就lis后直接从前往后扫就行了.. 注意输出方案不要写错..(wa了好多发...) 拓展:同时如果求答案的字典序最小,那么我们可以先对所有元素排序,然后一个个去试,即维护当前的lis长度,看当前的这个点是否能被接上(因为排序后是单调的,lis也是单调的) #include <cstd…
原题 Given a nested list of integers, return the sum of all integers in the list weighted by their depth. Each element is either an integer, or a list -- whose elements may also be integers or other lists. Example 1: Given the list [[1,1],2,[1,1]], ret…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcode-cn.com/problems/nested-list-weight-sum-ii/ 题目描述 Given a nested list of integers, return the sum of all integers in the list weighted by their depth.…
http://poj.org/problem?id=1694 (题目链接) 题意 一棵树,现在往上面放石子.对于一个节点x,只有当它的直接儿子都放满石子时,才能将它直接儿子中的一个石子放置x上,并回收其它石子.问最少需要多少个石子才能将石子放到根节点上. Solution 显然,贪心.数据范围小的可怜,用f[x]表示将石子放到节点x需要的最小石子数.然后对于一个节点的儿子节点,先放f[x]大的,再放小的. 细节 多组数据清空数组 代码 // poj1694 #include<algorithm>…
http://poj.org/problem?id=1738 (题目链接) 题意 一排n堆石子,合并两堆石子的代价为两堆石子总数之和.问将所有石子合并为一堆所需要的最小代价. Solution 本来想用刚学的四边形不等式练练手的,没想到n的范围竟然是50000,数组都开不下啊..只好去看了下那个不明觉厉的GarsiaWachs.具体做法参见:http://blog.csdn.net/acdreamers/article/details/18043897.也真的是奇葩.. 代码 // poj173…
http://poj.org/problem?id=1740 (题目链接) 男人八题之一 题意 对于n堆石子,每堆若干个,两人轮流操作,每次操作分两步,第一步从某堆中去掉至少一个,第二步(可省略)把该堆剩余石子的一部分分给其它的某些堆.最后谁无子可取即输. Solution 首先我们考虑两堆相等的情况,一定是谁取谁输,因为对方永远可以做对称的操作.对于四堆,1.2堆相等,3.4堆相等的情况,一定也是先手输,后手也只需要做对称的操作(在先手取石子的对称堆中取相同多的石子,并把和先手等量的石子分给先…
一.质点系重心公式 x=(x1*m1+x2*m2+x3*m3.....xn*mn)/M  (M=m1+m2+m3+m4...+mn) 二.三角形重心 可直接求得,但在多边形剖分中 各三角形的质点的质量大小不一样 质量大小等于三角形面积. 三.多边形重心 三角形剖分+任意点的三角形剖分+三角形重心+质点系重心公式+任意点的三角形剖分 所以很容易知道一种很优美的计算公式(看代码) #include <cstdio> #include <cstdlib> #include <cma…
题目描述 在学会了如何玩尼姆游戏之后,迈克开始尝试另一种看起来很多的石头游戏. 简单点. 游戏是这样的:两个玩家用一堆n块石头开始游戏.他们轮流从堆里取石头,每次至少取一块石头 一堆又一堆,每次他们至少拿走一块石头.先走的人最多能拿到. N-1石头作为他的第一步.从那时起,一个玩家最多能拿到k倍的石头. 他的对手上次赢了.例如,如果一个玩家在轮到他的时候拿到了m块石头,那么另一个玩家就会拿到另一个. 玩家下次最多可以拿km的石头.拿最后一块石头的人赢了这场比赛. 假设这两个球员总是采取最好的动作…
题意:dingyeye喜欢和你玩石子游戏.dingyeye有一棵n个节点的有根树,节点编号为0到n−1,根为0号节点. 游戏开始时,第i个节点上有a[i]个石子.两位玩家轮流操作,每次操作玩家可以选择一个节点,并将该节点上的一些石子(个数不能为0)移动到它的父亲节点上去. 如果轮到某位玩家时,该玩家没有任何合法的操作可以执行,则判负.你在游戏中执先手,你想知道当前局面你能否必胜. n<=1e5,0<=a[i]<=134217728 思路: 设根节点的深度为0,将所有深度为奇数的节点的石子…
problem 1021. Remove Outermost Parentheses 参考 1. Leetcode_easy_1021. Remove Outermost Parentheses; 完…
problem 1022. Sum of Root To Leaf Binary Numbers 参考 1. Leetcode_easy_1022. Sum of Root To Leaf Binary Numbers; 完…
problem 1025. Divisor Game 参考 1. Leetcode_easy_1025. Divisor Game; 完…
problem 1029. Two City Scheduling 参考 1. Leetcode_easy_1029. Two City Scheduling; 完…
problem 1030. Matrix Cells in Distance Order 参考 1. Leetcode_easy_1030. Matrix Cells in Distance Order; 完…
problem 1033. Moving Stones Until Consecutive 参考 1. Leetcode_easy_1033. Moving Stones Until Consecutive; 完…
problem 1037. Valid Boomerang 参考 1. Leetcode_easy_1037. Valid Boomerang; 完…
problem 1042. Flower Planting With No Adjacent 参考 1. Leetcode_easy_1042. Flower Planting With No Adjacent; 完…
problem 1047. Remove All Adjacent Duplicates In String 参考 1. Leetcode_easy_1047. Remove All Adjacent Duplicates In String; 完…
problem 1051. Height Checker solution class Solution { public: int heightChecker(vector<int>& heights) { vector<int> orders = heights; sort(orders.begin(), orders.end()); ; ; i<heights.size(); i++) { if(heights[i]!=orders[i]) res++; } r…
problem 1071. Greatest Common Divisor of Strings solution class Solution { public: string gcdOfStrings(string str1, string str2) { return (str1+str2==str2+str1) ? (str1.substr(, gcd(str1.size(), str2.size()))) : ""; } }; 参考 1. Leetcode_easy_1071…