pile

875. Koko Eating Bananas

风格不统一 提交于 2020-02-20 07:02:43
Koko loves to eat bananas. There are N piles of bananas, the i -th pile has piles[i] bananas. The guards have gone and will come back in H hours. Koko can decide her bananas-per-hour eating speed of K . Each hour, she chooses some pile of bananas, and eats K bananas from that pile. If the pile has less than K bananas, she eats all of them instead, and won't eat any more bananas during this hour. Koko likes to eat slowly, but still wants to finish eating all the bananas before the guards come back. Return the minimum integer K such that she can eat all the bananas within H hours. Example 1:

HDU-6036 Division Game(ntt模板)

一曲冷凌霜 提交于 2020-01-30 12:55:34
题面 Description There are \(k\) piles of stones in a circle, numbered from \(0\) to \(k - 1\) , where the number of the stones in each pile is \(n\) initially. You can do some round operations, where the initial round is numbered as the \(1\) -st round. The operation of the \(i\) -th round is to modify the pile of stones numbered \((i - 1) \bmod k\) . In each round, you should remove from this pile some stones (at least one stone), satisfying that the number of stones in this pile before this operation is a multiple of the number of stones in this pile after operation, which means that you

递归和快速排序

感情迁移 提交于 2020-01-22 05:48:59
文章目录 递归 问题描述 基线条件和递归条件 栈 调用栈 递归调用栈 小结 快速排序 示例1 问题描述 欧几里得算法 使用D&C解决问题的两个步骤: 示例2 快速排序 工作原理 代码 小结 递归 问题描述 假设你在祖母的阁楼中翻箱倒柜,发现了一个上锁的神秘手提箱。祖母告诉你,钥匙很可能在下面这个盒子里,这个盒子里有盒子,而盒子里的盒子又有盒子。钥匙就在某个盒子中。为找到钥匙,你将使用什么算法? 方法一: 创建一个要查找的盒子堆。 从盒子堆取出一个盒子,在里面找。 如果找到的是盒子,就将其加入盒子堆中,以便以后再查找。 如果找到钥匙,则大功告成! 回到第二步。 方法二: 检查盒子中的每样东西。 如果是盒子,就回到第一步。 如果是钥匙,就大功告成! 第一种方法使用的是while循环:只要盒子堆不空,就从中取一个盒子,并在其中仔细查找。 def look_for_key ( main_box ) : pile = main_box . make_a_pile_to_look_through ( ) while pile is not empty : box = pile . grab_a_box ( ) for item in box : if item . is_a_box ( ) : pile . append ( item ) elif item . is_a_key ( ) :

用表情包的方式打开codeforces 1191 D --- Tokitsukaze, CSL and Stone Game #573 (Div. 2)

独自空忆成欢 提交于 2019-12-22 15:36:47
D. Tokitsukaze, CSL and Stone Game 题目链接: http://codeforces.com/contest/1191/problem/D 1 D. Tokitsukaze, CSL and Stone Game 2 3 time limit per test1 second 4 5 memory limit per test256 megabytes 6 7 inputstandard input 8 9 outputstandard output 10 11 Tokitsukaze and CSL are playing a little game of stones. 12 13 In the beginning, there are n piles of stones, the i-th pile of which has ai stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are

LeetCode 875. Koko Eating Bananas

一曲冷凌霜 提交于 2019-12-04 19:50:56
原题链接在这里: https://leetcode.com/problems/koko-eating-bananas/ 题目: Koko loves to eat bananas. There are N piles of bananas, the i -th pile has piles[i] bananas. The guards have gone and will come back in H hours. Koko can decide her bananas-per-hour eating speed of K . Each hour, she chooses some pile of bananas, and eats K bananas from that pile. If the pile has less than K bananas, she eats all of them instead, and won't eat any more bananas during this hour. Koko likes to eat slowly, but still wants to finish eating all the bananas before the guards come back. Return the minimum integer K such

global variable in main not getting recognised in another function in python

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: code below creates a layout and displays some text in the layout. Next the layout is displayed on the console screen using raw display module from urwid library. However running the code fails as a global variable ui, declared in main, is not recognised in another function. Error code on running is : Traceback (most recent call last): File "./yamlUrwidUIPhase6.py", line 97, in <module> main() File "./yamlUrwidUIPhase6.py", line 90, in main form = FormDisplay() File "./yamlUrwidUIPhase6.py", line 23, in __init__ palette = ui.register_palette(

Build a pile of Cubes

匿名 (未验证) 提交于 2019-12-02 23:40:02
version_1: def find_nb(m): # your code ii = 1 total = 0 while total < m: total = sum(each**3 for each in range(ii)) ii += 1 if total == m: result = ii-2 else: result = -1 return result version_2: def find_nb(m): # your code i = 1 while m>0: m = m - i**3 i += 1 return -1 if m<0 else i-1

cf---A. Amusing Joke

匿名 (未验证) 提交于 2019-12-02 23:38:02
版权声明:Ls---zzz https://blog.csdn.net/weixin_43400325/article/details/90343372 So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two “New Year and Christmas Men” meet, thear assistants cut out of cardboard the letters from the guest’s name and the host’s name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters’ names. Then he may have shuffled the letters and put them in one pile in front of the door. The next morning it was

Burst Balloons

会有一股神秘感。 提交于 2019-11-29 06:13:50
原题链接在这里: https://leetcode.com/problems/minimum-cost-to-merge-stones/ 题目: There are N piles of stones arranged in a row. The i -th pile has stones[i] stones. A move consists of merging exactly K consecutive piles into one pile, and the cost of this move is equal to the total number of stones in these K piles. Find the minimum cost to merge all piles of stones into one pile. If it is impossible, return -1 . Example 1: Input: stones = [3,2,4,1], K = 2 Output: 20 Explanation: We start with [3, 2, 4, 1]. We merge [3, 2] for a cost of 5, and we are left with [5, 4, 1]. We merge [4, 1] for a cost of

A. Three Piles of Candies ( Codeforces Round #575 )

可紊 提交于 2019-11-28 20:53:14
Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and Bob as they want: for example, it is possible that Alice takes the whole pile, and Bob gets nothing from it. After taking the candies from the piles, if Alice has more candies than Bob, she discards some candies so that the number of candies she has is equal to the number of candies Bob has. Of course, Bob does the same if he has more candies.