08 2014 档案

摘要:https://www.hackerrank.com/contests/w9/challenges/lexicographic-steps这题还是折腾很久的。题目意思相当于,比如有两个1两个0,那么找组成的数里第k大的。想法就是,如上例,假如K为4,那么先看后两位够了么C(2,2)=1,不够,那么看... 阅读全文
posted @ 2014-08-30 19:23 阿牧遥 阅读(254) 评论(0) 推荐(0)
摘要:https://www.hackerrank.com/contests/infinitum-aug14/challenges/jim-beam学习了线段相交的判断法。首先是叉乘,叉乘的几何意义是有向的平行四边形的面积(除以2就是三角形的面积)。如果ABD和ABC正负相反,说明C和D在AB两侧,同样的... 阅读全文
posted @ 2014-08-23 11:03 阿牧遥 阅读(288) 评论(0) 推荐(0)
摘要:https://www.hackerrank.com/challenges/service-lane用RMQ做的,其实暴力也能过~#include #include #include using namespace std;int main() { int n, t; cin >> n ... 阅读全文
posted @ 2014-08-18 21:29 阿牧遥 阅读(163) 评论(0) 推荐(0)
摘要:https://www.hackerrank.com/contests/w1/challenges/volleyball-match此题不错,首先可以看出是DP,S(x, y)= S(x - 1, y) + S(x, y - 1)。然后比赛结束状态需要认真判断。三来,最后数据量很大(接近10^9)远... 阅读全文
posted @ 2014-08-16 22:21 阿牧遥 阅读(597) 评论(0) 推荐(1)
摘要:https://www.hackerrank.com/contests/w1/challenges/maximizing-xor/找了半天规律,答案竟然是暴力,伤感。我找到的方法是利用规律2^x XOR 2^x - 1会最大,感觉稍微效率高点。int maxXor(int l, int r) { i... 阅读全文
posted @ 2014-08-16 01:24 阿牧遥 阅读(294) 评论(0) 推荐(0)
摘要:https://www.hackerrank.com/contests/w2/challenges/cut-the-tree树分成两部分,求两部分差最小。一开始想多了,后来其实求一下总和,求一下分部的和就行了。#include #include #include #include #include ... 阅读全文
posted @ 2014-08-16 00:05 阿牧遥 阅读(323) 评论(0) 推荐(0)
摘要:https://www.hackerrank.com/contests/w2/challenges/manasa-and-stones简单题。#includeusing namespace std;int main() { int T; cin >> T; while (T--) ... 阅读全文
posted @ 2014-08-15 20:22 阿牧遥 阅读(184) 评论(0) 推荐(0)
摘要:https://www.hackerrank.com/contests/w3/challenges/sam-and-substringsDP。注意到以N[i]结尾的每个字符串的子数字和有规律:53125 | 3 53 | 1 31 531 | 2 12 312 5312sd[2] = 1 + 31 ... 阅读全文
posted @ 2014-08-14 18:19 阿牧遥 阅读(409) 评论(0) 推荐(1)
摘要:https://www.hackerrank.com/contests/w3/challenges/the-love-letter-mystery简单题。#include #include #include using namespace std;int main() { int N; cin >>... 阅读全文
posted @ 2014-08-14 15:46 阿牧遥 阅读(207) 评论(0) 推荐(0)
摘要:https://www.hackerrank.com/contests/w4/challenges/crush第一眼觉得要用线段树,但据说会超时。其实这个可以通过生成pair排序来做。#include #include #include #include using namespace std;in... 阅读全文
posted @ 2014-08-14 15:20 阿牧遥 阅读(340) 评论(0) 推荐(0)
摘要:简单题。#include #include using namespace std;int main() { int T; cin >> T; while (T--) { string s; cin >> s; int l = 0; ... 阅读全文
posted @ 2014-08-14 00:08 阿牧遥 阅读(225) 评论(0) 推荐(0)
摘要:https://www.hackerrank.com/contests/w5/challenges/closest-number简单题。#include #include using namespace std;int main() { int T; cin >> T; while... 阅读全文
posted @ 2014-08-13 18:24 阿牧遥 阅读(260) 评论(0) 推荐(0)
摘要:https://www.hackerrank.com/contests/w5/challenges简单题,注意整数的0次方是1,奇数。#include #include using namespace std;int main() { int N; cin >> N; vector... 阅读全文
posted @ 2014-08-13 17:23 阿牧遥 阅读(296) 评论(0) 推荐(0)
摘要:https://www.hackerrank.com/contests/w6/challenges/consecutive-subsequences求数组中被k整除的子段和有几个。这个要利用sum[i..j] = sum[j] - sum[i-1],注意这样还要保留一个sum[-1]=0(根据下标的... 阅读全文
posted @ 2014-08-13 13:28 阿牧遥 阅读(465) 评论(0) 推荐(0)
摘要:https://www.hackerrank.com/contests/w6/challenges/acm-icpc-team这道题在contest的时候数据量改小过,原来的数据量需要进行优化才能过。参考了:http://chasethered.com/2014/07/hackerrank-week... 阅读全文
posted @ 2014-08-12 23:58 阿牧遥 阅读(348) 评论(0) 推荐(0)
摘要:https://www.hackerrank.com/contests/w7/challenges/chocolate-in-boxNim Game:http://www.cdf.toronto.edu/~ajr/270/probsess/03/strategy.html策略是将数组变成XOR为0的... 阅读全文
posted @ 2014-08-12 18:17 阿牧遥 阅读(298) 评论(0) 推荐(0)
摘要:https://www.hackerrank.com/contests/w7/challenges/die-hard-3首先,发现c #include using namespace std;int gcd(int a, int b) { if (a % b == 0) { return b; }... 阅读全文
posted @ 2014-08-12 10:47 阿牧遥 阅读(202) 评论(0) 推荐(0)
摘要:https://www.hackerrank.com/contests/w8/challenges/gneck有点意思。是DP,最优解包含最优子问题。F(X)=F(X-1)+F(X-3)。因为F(X-1)右边放个“R”和F(X-3)右边放"RRB"是左右可以互推的,包含全了最右是R和B的两种情况。#... 阅读全文
posted @ 2014-08-11 20:16 阿牧遥 阅读(236) 评论(0) 推荐(0)
摘要:https://www.hackerrank.com/contests/w8/challenges/john-and-gcd-list简单题,GCD和LCM。#include #include using namespace std;int gcd(int a, int b) { if (a % b... 阅读全文
posted @ 2014-08-11 13:46 阿牧遥 阅读(204) 评论(0) 推荐(0)
摘要:https://www.hackerrank.com/contests/w8/challenges/counter-game关键是二分查找等于或最接近的小于target的数。可以使用和mid+1判断来比较~ 另有一种做法如下:http://stackoverflow.com/questions/65... 阅读全文
posted @ 2014-08-11 12:05 阿牧遥 阅读(392) 评论(0) 推荐(0)
摘要:http://community.topcoder.com/stat?c=problem_statement&pm=12975简单题#include #include using namespace std;class EllysNumberGuessing {public: int getNumb... 阅读全文
posted @ 2014-08-10 17:55 阿牧遥 阅读(164) 评论(0) 推荐(0)
摘要:http://community.topcoder.com/stat?c=problem_statement&pm=12967计算一个字符串里Palindrome的数量。我的DP方法需要n^2的空间。#include #include using namespace std;class Palind... 阅读全文
posted @ 2014-08-09 21:05 阿牧遥 阅读(145) 评论(0) 推荐(0)
摘要:http://community.topcoder.com/stat?c=problem_statement&pm=12995简单题class PackingBallsDiv2 {public: int minPacks(int R, int G, int B) { int sum = 0; s... 阅读全文
posted @ 2014-08-09 20:33 阿牧遥 阅读(158) 评论(0) 推荐(0)
摘要:http://community.topcoder.com/stat?c=problem_statement&pm=13035矩阵棋盘的题,比较典型。可以定两条column夹住,然后上下扫,上下扫过程中有一点DP的东西,这样负责度是o(n^3)#include #include #include u... 阅读全文
posted @ 2014-08-09 12:59 阿牧遥 阅读(203) 评论(0) 推荐(0)
摘要:第一题是整数的方阵,求其中的子方阵,和最大。返回最大和以及子方阵宽度。因为做了topcoder的题,所以比较顺手,O(n^3)的复杂度。pair maxiSum(vector > &a) { //first is n second is sum int N = a.size(); in... 阅读全文
posted @ 2014-08-08 22:50 阿牧遥 阅读(295) 评论(0) 推荐(0)
摘要:http://community.topcoder.com/stat?c=problem_statement&pm=13005好题。最暴力是试验2^n种跳法。然后有从结果入手,那么最终的左右是i, j,有n^2种(每种4个跳法),然后花O(n)的时间去验证。最后的正解比较有意思,就是观察到必须向里跳... 阅读全文
posted @ 2014-08-08 17:14 阿牧遥 阅读(192) 评论(0) 推荐(0)
摘要:http://community.topcoder.com/stat?c=problem_statement&pm=13040DFS集合全排列+LCM和GCD。但事实上,有更简单的算法,列在下面,就是观察到不能整除x的对我们无效。#include #include using namespace s... 阅读全文
posted @ 2014-08-08 15:23 阿牧遥 阅读(150) 评论(0) 推荐(0)
摘要:http://community.topcoder.com/stat?c=problem_statement&pm=13091解方程,对中国孩子太简单了。#include #include using namespace std;class LongLongTripDiv2 {public: ... 阅读全文
posted @ 2014-08-08 14:48 阿牧遥 阅读(147) 评论(0) 推荐(0)
摘要:http://community.topcoder.com/stat?c=problem_statement&pm=13147此题关键在于发现ABAB的组合最多有26*26种,可以穷举,然后用判断子序列~#include #include using namespace std;class Long... 阅读全文
posted @ 2014-08-08 14:29 阿牧遥 阅读(135) 评论(0) 推荐(0)
摘要:http://lintcode.com/en/problem/majority-number-iii/此题是黑帮火并的思想,就是如果有k个不同的元素,那么把他们全去掉,不影响剩下的元素中的“众数”。如果“众数”在k个里面,不影响,不在,也不影响。原题确认只有一个“众数”,那么就不用再扫一遍了。当然也... 阅读全文
posted @ 2014-08-07 22:45 阿牧遥 阅读(964) 评论(3) 推荐(0)
摘要:https://oj.leetcode.com/problems/reverse-words-in-a-string/分三步,1. reverse line; 2. reverse words; 3. erase extra spaces;class Solution {public: voi... 阅读全文
posted @ 2014-08-02 20:14 阿牧遥 阅读(178) 评论(0) 推荐(0)
摘要:https://www.topcoder.com/stat?c=problem_statement&pm=13146&rd=15852// Need carefully calc the shift and the final index#include using namespace std;cl... 阅读全文
posted @ 2014-08-02 17:39 阿牧遥 阅读(172) 评论(0) 推荐(0)
摘要:C++优先队列类似队列,但是在这个数据结构中的元素按照一定的断言排列有序。它的头文件为。由于适配器不支持迭代,一个 priority_queue 将有没有关联的迭代器。函数列表:empty() 如果优先队列为空,则返回真 pop() 删除第一个元素 push() 加入一个元素 size() 返回优先... 阅读全文
posted @ 2014-08-02 15:54 阿牧遥 阅读(231) 评论(0) 推荐(0)
摘要:https://community.topcoder.com/stat?c=problem_statement&pm=13192#include #include #include using namespace std;class BoxesDiv2{public: vector power2; ... 阅读全文
posted @ 2014-08-02 15:53 阿牧遥 阅读(186) 评论(0) 推荐(0)
摘要:http://community.topcoder.com/stat?c=problem_statement&pm=12107此题想了半天,当时瞥到了Greedy,所以就想着贪心,最后的方法又纸上画了一下应该是对的。就是排序后依次看是不是满足要求。证明就是如果对数字X,有a和b都能够通过增加k的倍数... 阅读全文
posted @ 2014-08-02 08:33 阿牧遥 阅读(360) 评论(0) 推荐(0)
摘要:http://community.topcoder.com/stat?c=problem_statement&pm=13245就是有字符串,里面的字符可以随意两两消除,如果不等的话,那么最后如果留下一个字符,这个字符就是winning letter。如果任意方法消除都是这个winning lette... 阅读全文
posted @ 2014-08-02 07:50 阿牧遥 阅读(201) 评论(0) 推荐(0)
摘要:http://community.topcoder.com/stat?c=problem_statement&pm=13243就是能否通过把字符串中的'X'替换成"()", "[]", and "{}"来变成合法的括号字符串,"([]X()[()]XX}[])X{{}}]"Returns: "pos... 阅读全文
posted @ 2014-08-01 23:50 阿牧遥 阅读(184) 评论(0) 推荐(0)