gold

USACO 2016 January Contest Gold T1: Angry Cows

孤者浪人 提交于 2020-03-24 02:41:00
题目大意 奶牛Bessie设计了一个游戏:“愤怒的奶牛”。游戏的原型是:有一些可爆炸的草堆分布在一条数轴的某些坐标上,玩家用弹弓把一头奶牛发射到数轴上。奶牛砸到数轴上的冲击波会引发附近的草堆爆炸,而被引爆的草堆可能会引爆其他草堆。游戏的目标是玩家用一只奶牛炸掉所有的草堆。 有N (2≤N≤50,000) 个草堆在数轴的不同位置,坐标为x1,x2,….,xn。如果玩家以能量R把奶牛发射到坐标x,就会引爆半径R及以内的的草堆,即坐标范围[x−R,x+R]的草堆都会燃爆,每个被奶牛引爆的草堆又会2次引爆半径R-1及以内的的草堆,2次引爆的草堆又会3次引爆半径R-2及以内的的草堆...直到一次引爆后没有其他草堆被波及或半径为0。 现在只有1头奶牛,能量为R,请计算如果要引爆所有的草堆,最小的R是多少? 题目分析 观察数据范围,n为50000,一般会向O(nlogn)的复杂度思考,所以我们考虑进行二分。 我们先用 f[i] 记录以i为中心可以向左覆盖前i-1个点的最小半径。 再用 g[i] 记录以i为中心可以向右覆盖至第n个点的最小半径。 那么我们二分枚举第一次爆炸的半径r。 枚举i,即第i个草堆为这次爆炸的左边界,再在左边界到右边界的草堆中枚举j,如果f[i]+1<=r并且g[i]+1<=r,则说明这个方案可行。 考虑再次优化,因为 f数组,g数组 与 草堆坐标 的差都具有单调性(i越大

LightOJ-1030-Discovering Gold

谁都会走 提交于 2020-02-13 03:06:38
链接: https://vjudge.net/problem/LightOJ-1030 题意: You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave can contain any amount of gold. Initially you are in position 1. Now each turn you throw a perfect 6 sided dice. If you get X in the dice after throwing, you add X to your position and collect all the gold from the new position. If your new position is outside the cave, then you keep throwing again until you get a suitable result. When you reach the Nth position you stop your journey. Now you are given the information about the cave, you have to

CareerCup maximum sum in n*n num array

大憨熊 提交于 2020-01-13 01:08:59
Given a n*n array like the following example. A man could only move up down left and right without oblique movement. BTW, the man could only arrive when num[i][j] is a number instead of '*'. At the same time, no num circle could be generated in n*n array. How could we get the maximum num sum? nums = [['*','*','4','*','*','1','*'], ['*','1','2','3','*','*','*'], ['*','1','*','3','*','*','*'], ['*','*','*','*','1','*','*'], ['*','*','1','1','3','1','*'], ['*','*','3','*','88','*','*'], ['*','*','1','1','*','*','1233']]; -------------------------------------------------- Solution: The condition

深度学习NLP任务中一些功能性代码块pytoch实现记录

喜你入骨 提交于 2020-01-10 10:58:18
有一些NLP任务中需要实现一些小功能,还是不是很熟练,但是自己写起来又有点难度,故此记录下来。以后每遇到新的就添加上来——不定时更新添加! 1、由predictions和labels计算准确率、正确率、recall和F1 #准确率的计算 correct += (predict == label).sum().item() total += label.size(0) train_acc = correct / total #精确率、recall和F1的计算 for i in range(self.number_of_classes): if i == self.none_label: continue #TP和FP self._true_positives += ((predictions==i)*(gold_labels==i)*mask.bool()).sum() self._false_positives += ((predictions==i)*(gold_labels!=i)*mask.bool()).sum() #TN和FN self._true_negatives += ((predictions!=i)*(gold_labels!=i)*mask.bool()).sum() self._false_negatives += ((predictions!=i)*

HDU-4341 Gold miner 题解

被刻印的时光 ゝ 提交于 2019-12-27 16:02:39
题目大意 黄金矿工的游戏,不过每个金块可以看做是质点,没有大小,给出每个金块的坐标、抓取所花费的时间(包括返回的时间),以及价值,其中有一些金块可能会共线。求在规定时间内所获得的最大价值。 样例 样例输入 1 3 10 1 1 1 1 2 2 2 2 1 3 15 9 样例输出 1 3 样例 1 说明 1和2共线,同时抓取价值最大 样例输入2 3 10 1 1 13 1 2 2 2 2 1 3 4 7 样例输出2 7 样例 2 说明 1和2共线,抓2必须先抓1,时间不够,因此只抓3最优。 分析 涉及到共线若干个点共线的问题,因此如果若干个点共线,要抓下面的金块的话,必须把它上面的所有的都抓完,所需要的时间为抓取所有金块的时间总和。因此可以把下面的金块的花费和价值保存成包括它自己在内的上面的左右金块的花费和价值总和,这样的话,如果抓这个金块,那么就代表上面的所有金块都已经抓取,因此共线的所有金块可以认为最多只抓取其中一个,这样来看,每条斜率即为一个分组,直接跑分组背包就可以 另外就是处理共线问题,初中知识,不多说了 由于下面的金块的属性是上面的所有金块的前缀和,因此既要知道共线,又要知道金块上下的相对位置,因此分组之前需要对金块按照纵坐标升序排列(只需要按照纵坐标排序即可) 代码 // 对所有的gold进行分组,重新计算价值和时间 void Divide() { for (int i

《python编程快速上手——让繁琐的工作自动化》,实践项目5.6.2 针对好玩游戏物品清单

不羁的心 提交于 2019-12-14 22:15:22
体检教材: def addToInventory ( inventory , addedItems ) : for i in addedItems : inventory . setdefault ( i , 0 ) inventory [ i ] += 1 print ( inventory ) inv = { 'gold coin' : 42 , 'rope' : 1 } dragonLoot = [ 'gold coin' , 'dagger' , 'gold coin' , 'gold coin' , 'ruby' ] inv = addToInventory ( inv , dragonLoot ) 输出如下: 具体情节可参考我的博客,“《python编程快速上手——让繁琐的工作自动化》,5.1.5 setdefault()方法,计算字符串中字符出现个数总结” { 'gold coin' : 45 , 'rope' : 1 , 'dagger' : 1 , 'ruby' : 1 } 思路基本一样,不再详细记载,这里自己发现了一个有趣的现象,对我自己的学习和理解有一定帮助,记下来: def addToInventory ( inventory , addedItems ) : for i in addedItems : inventory . setdefault ( i

一种概率变化的骰子模型

社会主义新天地 提交于 2019-12-10 13:40:17
玩家初始金币数为100 有一面骰子,玩家投掷到2,3,5 点的时候,获得金币数为当前金币数*对应的点数 其余点数,获得金币数为,当前金币数*0.5 若连续两次得到0.5的点数,则投掷结束 设计规则,计算期望 代码如下 import numpy as np #导入包名 import matplotlib.pyplot as plt win_time=np.array([2,3,5,0.5])#各个奖励 ls_gold=[] best_gold=[] for j in range(5): #单次游戏 i=0 d=0.1 score=[] win_gold=100 gold_record=[] while True: x = (1 - d)*0.5 #(*2点*) b = (1 - d)*0.3 #(*3点*) c = (1 - d)*0.2 #(*5点*) score.append(np.random.choice(a=win_time, size=1, replace=True, p=[x, b, c ,d]))#注意不要使用Append=() win_gold=win_gold*float(score[i])#获得奖金数等于上次奖金*本次奖励倍数 gold_record.append(win_gold)#用来记录投掷次数不同时获得奖金数,寻找最佳停止时间 if i>0 and

Python equivalent of D3.js

ⅰ亾dé卋堺 提交于 2019-12-09 15:20:00
http://brandonrose.org/ Python equivalent of D3.js Ask Question Asked 7 years, 1 month ago Active 10 months ago Viewed 90k times 99 76 Can anyone recommend a Python library that can do interactive graph visualization? I specifically want something like d3.js but for python and ideally it would be 3D as well. I have looked at: NetworkX - it only does Matplotlib plots and those seem to be 2D. I didn't see any sort of interactiveness, like one that d3.js gives, such as pulling nodes around. graph-tool - it does only 2D plots and has very slow interactive graphs. python graph d3.js graph-tool

leetcode 1219. Path with Maximum Gold

瘦欲@ 提交于 2019-12-05 01:57:22
In a gold mine grid of size m * n , each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can walk one step to the left, right, up or down. You can't visit the same cell more than once. Never visit a cell with 0 gold. You can start and stop collecting gold from any position in the grid that has some gold. Example 1: Input: grid = [[0,6,0],[5,8,7],[0,9,0]] Output: 24

js实现tab栏切换效果(一)

人走茶凉 提交于 2019-12-03 05:08:44
利用javascript实现tab栏切换效果, 其中原理“置之死地而后生”,先把所有人干掉,自己再复活。 直接上代码: <!DOCTYPE html> < html > < head > < meta charset = "UTF-8" > < title > </ title > < style type = "text/css" > * { margin : 0 ; padding : 0 ; } .box { width : 300 px ; margin : 100 px auto ; border : 1 px solid #ccc ; } .content div { width : 100 % ; height : 300 px ; background-color : gold ; display : none ; line-height : 300 px ; text-align : center ; } .gold { background-color : gold ; } </ style > < script type = "text/javascript" > window.onload = function () { var btns = document.getElementsByTagName( "button" ); var divs =