摘要: 题目描述: 有n个物品的重量和价值分别为Wi和Vi。从中选出k个物品使得单位重量的价值最大。 例如: n=3 k=2 (w,v)={(2,2) , (5,3) , (2,1) } 输出应为0.75 分析: 一般我们最先想到的就是把物品按照单位价值进行排序,从大到小贪心的进行选取。但是这种方法对于样例 阅读全文
posted @ 2017-07-19 21:08 渡…… 阅读(260) 评论(0) 推荐(0) 编辑
摘要: " 题目链接 " Description Farmer John has built a new long barn, with N (2 include include using namespace std; int N,M; int x[100009]; bool C(int d) { int 阅读全文
posted @ 2017-07-19 20:34 渡…… 阅读(197) 评论(0) 推荐(0) 编辑
摘要: " 题目链接 " Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Committee has volunteered and has 阅读全文
posted @ 2017-07-19 19:24 渡…… 阅读(212) 评论(0) 推荐(0) 编辑
摘要: Problem You have been invited to the popular TV show "Would you like to be a millionaire?". Of course you would! The rules of the show are simple: Bef 阅读全文
posted @ 2017-07-19 17:02 渡…… 阅读(897) 评论(0) 推荐(0) 编辑
摘要: 一个监狱里有P个并排着的牢房,从左往右一次编号为1,2,…,P。最初所有牢房里面都住着一个囚犯。现在要释放一些囚犯。如果释放某个牢房里的囚犯,必须要贿赂两边所有的囚犯一个金币,直到监狱的两端或者空牢房为止。现在要释放a1,a2,...,aQ号囚犯,如何选择释放的顺序,使得使用的金币最少。 思路: 其 阅读全文
posted @ 2017-07-19 11:52 渡…… 阅读(1832) 评论(0) 推荐(2) 编辑
摘要: Problem You are given an N x N matrix with 0 and 1 values. You can swap any two adjacent rows of the matrix. Your goal is to have all the 1 values in 阅读全文
posted @ 2017-07-19 10:22 渡…… 阅读(362) 评论(0) 推荐(0) 编辑
摘要: 快速幂取模算法 所谓的快速幂,实际上是快速幂取模的缩写,简单的说,就是快速的求一个幂式的模(余)。在程序设计过程中,经常要去求一些大数对于某个数的余数,为了得到更快、计算范围更大的算法,产生了快速幂取模算法。 我们先从简单的例子入手:求x^n % mod 。 算法1.首先直接地来设计这个算法: 本算 阅读全文
posted @ 2017-07-19 08:51 渡…… 阅读(2432) 评论(0) 推荐(0) 编辑