随笔分类 -  Algorithm

上一页 1 2 3 4 5 6 7 8 9 ··· 16 下一页
classic algorithm, problem
摘要:Given a 2d grid map of'1's (land) and'0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent ... 阅读全文
posted @ 2015-04-09 16:31 卖程序的小歪 阅读(209) 评论(0) 推荐(0)
摘要:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping yo... 阅读全文
posted @ 2015-04-09 16:23 卖程序的小歪 阅读(136) 评论(0) 推荐(0)
摘要:题目2 : Professor Q's Software时间限制:10000ms单点时限:1000ms内存限制:256MB描述Professor Q develops a new software. The software consists of N modules which are numbe... 阅读全文
posted @ 2015-04-04 22:48 卖程序的小歪 阅读(454) 评论(0) 推荐(0)
摘要:lower_boundlower_bound(begin, end, target)用来查找一个已排序的序列中[begin, end)第一个大于等于target的元素index。数组A如下:value: 1, 2, 2, 3, 4, 5, 5, 6, 7index: 0, 1, 2, 3, 4, 5... 阅读全文
posted @ 2015-04-02 14:15 卖程序的小歪 阅读(1562) 评论(0) 推荐(0)
摘要:class Solution {public: int findMin(vector &num) { int L = 0, R = num.size() - 1; while (L = num[R]) { int mid= (L+R)/2; ... 阅读全文
posted @ 2015-04-02 10:28 卖程序的小歪 阅读(169) 评论(0) 推荐(0)
摘要:#include #include #include #include #include #define MAX_N 10int d[MAX_N][MAX_N];int dp[1= 0) { return dp[S][v]; } if ((1>u) & 1)) { ... 阅读全文
posted @ 2015-03-13 20:01 卖程序的小歪 阅读(381) 评论(0) 推荐(0)
摘要:尼玛,数组偶数个数的时候取中位数是取中间两者中的前者,还tmd一直再算平均,卧槽#include #include #include #include using namespace std;int min(int a, int b) { return a a(na); for ... 阅读全文
posted @ 2015-03-10 15:54 卖程序的小歪 阅读(166) 评论(0) 推荐(0)
摘要:这场考试当年还参加了,当时直接用内置的排序了,否则自己写归并排序浪费时间啊,现在来练习一发。估计又有些节点没在链表里面,当时没考虑这个情况,所以一直有些case没过#include #include #include #include using namespace std;class Node {... 阅读全文
posted @ 2015-03-10 13:16 卖程序的小歪 阅读(212) 评论(0) 推荐(0)
摘要:又是排队模拟#include #include #include #include #include using namespace std;class Man {public: int arrive; int need; int start; Man(int a, int ... 阅读全文
posted @ 2015-03-09 21:52 卖程序的小歪 阅读(171) 评论(0) 推荐(0)
摘要:只能说看清题意很重要,md扯了半天是开始时间在17:00之前的可以而不是结束时间。另外代码里选取最小队列的过程(move_customers内)可以用priority_queue来加速,不过反正约定的数据量不大就直接遍历吧。#include #include #include #include #i... 阅读全文
posted @ 2015-03-09 15:00 卖程序的小歪 阅读(258) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 8 class Node { 9 public: 10 int data; 11 int next; 12 ... 阅读全文
posted @ 2015-03-09 00:57 卖程序的小歪 阅读(152) 评论(0) 推荐(0)
摘要:其实就是链表求交: 1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 8 class Node { 9 public:10 Node() : data(0), next(0) {}11 ... 阅读全文
posted @ 2015-03-03 23:24 卖程序的小歪 阅读(144) 评论(0) 推荐(0)
摘要:LIS,最长递增子序列说明见:http://blog.csdn.net/sdjzping/article/details/8759870 1 #include 2 #include 3 4 using namespace std; 5 6 int LIS(int* arr, int len)... 阅读全文
posted @ 2015-03-02 17:40 卖程序的小歪 阅读(316) 评论(0) 推荐(0)
摘要:class Solution {public: int titleToNumber(string s) { int len = s.length(); if(len == 0) { return 0; } retur... 阅读全文
posted @ 2015-01-27 23:59 卖程序的小歪 阅读(124) 评论(0) 推荐(0)
摘要:class Solution {public: int trailingZeroes(int n) { int count = 0; while (n) { count += n / 5; n /= 5; }... 阅读全文
posted @ 2015-01-27 23:53 卖程序的小歪 阅读(119) 评论(0) 推荐(0)
摘要:class BSTIterator {private: TreeNode* current; stack nodeStack;public: BSTIterator(TreeNode *root) { current = root; } /** @retu... 阅读全文
posted @ 2015-01-23 00:04 卖程序的小歪 阅读(148) 评论(0) 推荐(0)
摘要:class Solution {public: int maxProduct(int A[], int n) { if (A == NULL || n res) { res = tr; } if (tr ... 阅读全文
posted @ 2014-12-21 14:14 卖程序的小歪 阅读(125) 评论(0) 推荐(0)
摘要:class Solution {public: string convertToTitle(int n) { if (n 0) { n--; res = (char)(n % 26 + 'A') + res; n ... 阅读全文
posted @ 2014-12-21 13:17 卖程序的小歪 阅读(98) 评论(0) 推荐(0)
摘要:class Solution {public: int maximumGap(vector &num) { int len = num.size(); int gap = 0; sort(num.begin(), num.end()); ... 阅读全文
posted @ 2014-12-21 12:10 卖程序的小歪 阅读(222) 评论(0) 推荐(0)
摘要:class Solution {public: int compareVersion(string version1, string version2) { vector v1 = getVersionParts(version1); vector v2 = get... 阅读全文
posted @ 2014-12-19 20:00 卖程序的小歪 阅读(199) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 8 9 ··· 16 下一页