摘要:The answer byTuxdudeis perfect:http://stackoverflow.com/questions/11161465/existence-of-a-permutation-under-constraints-interview-street-manipulative-...
阅读全文
随笔分类 - HackerRank
摘要:More on data structure.#include #include #include #include #include #include #include #include using namespace std;typedef pair Point;struct DistComp{...
阅读全文
摘要:Classic and challenging DP! And you need combine several tricks together with DP to make it 100% pass.My main reference is here:https://github.com/hav...
阅读全文
摘要:Not hard, but with some amount of coding. Brutal-force would work: iterate each unique pair of points. And I used "y=ax+b" to check each point which s...
阅读全文
摘要:import reimport ioimport sysinput_stream = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')s = input_stream.readlines()s = "\n".join(s)pc = '(//.*...
阅读全文
摘要:So fun! It connects algorithm(regex) with real world usages!So basically speaking, C:pointer syntax, #include\scanf\typedef; Java: import\public class...
阅读全文
摘要:Really fun regex one.import ren = int(input())txt = ''for _ in range(n): str = input() txt = txt + strdict = {}all = re.findall(']*>', txt)for i...
阅读全文
摘要:A relatively more complex regex problem to work on. It is fun!import ren = input()for _ in range(n): str = raw_input() pl = '[+-]?([1-8]?[0-9]([...
阅读全文
摘要:Pretty classic greedy problem to work on. Here is how to approach it:1. "the smallest team is as large as possible." actually means, team members shou...
阅读全文
摘要:My intuition told me that it is a line-scan process.. and yes it is. First, we sort all (a,b,k) by index\start-end, then we do a line scan. And in C++...
阅读全文
摘要:Note this smart observation from Editorial: "M will be either P or Q or (A_i+A_j)/2"..Yea I know, my code is not condense enough..#include #include #i...
阅读全文
摘要:I guess the punch line of this one is Sieving for primes.#include #include #include #include #include #include #include #include using namespace std;v...
阅读全文
摘要:Apparently it is by a backwards derivation solution. Say energy at h[i] is e, the next energy at h[i+1] is 2*e - h[i+1] => e', so backwards, e = ceil(...
阅读全文
摘要:We match larger in array_a with smaller in array_b, by which we can have as even sum as possible, so we don't have too small sums.#include #include #i...
阅读全文
摘要:Apparently, more expensive flowers should be bought with lower coeff. (Greedy part), and any unbalanced assignment would cause extra cost.So the code ...
阅读全文
摘要:It is modulo version of "max sum of contiguous subarray". So similar pattern can be applied too, but with tricks regarding to modulo ops.I checked edi...
阅读全文
摘要:Good one to learn Binary Indexed Tree (Fenwick Tree). Simply grabbed the editorial's code but with comments.#include #include #include #include #inclu...
阅读全文
摘要:An ACM-level problem because it involves "advanced maths". It should not be marked as "Moderate". Other than that, it is a medium level DP one.*Math m...
阅读全文
摘要:This is my 1st 3D DP problem, and it should be an educational one. But, still tricky to me.Here is a good article:http://www.cnblogs.com/sunshineatnoo...
阅读全文
摘要:Solution 1:https://www.hackerrank.com/challenges/number-list/editorialReversed thought: total no. of subsets - no. of subsets without arr[i] > kSoluti...
阅读全文

浙公网安备 33010602011771号