06 2014 档案

摘要:Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ],... 阅读全文
posted @ 2014-06-29 17:53 OpenSoucre 阅读(197) 评论(0) 推荐(0) 编辑
摘要:参考Babylonian method(x0 越接*S的*方根越好)class Solution {public: int sqrt(double x) { if(x == 0) return 0; double root = x/2, tolerance = 1.... 阅读全文
posted @ 2014-06-29 17:30 OpenSoucre 阅读(199) 评论(0) 推荐(0) 编辑
摘要:Implement pow(x,n).明显的二分解决由于n不可能总是偶数, 如果n是正奇数,那么n个x的乘积等于两部分的乘积再乘以x 如果n是负奇数,那么n个x的乘积等于两部分乘积再乘以1/xclass Solution {public: double pow(double x, int ... 阅读全文
posted @ 2014-06-29 16:45 OpenSoucre 阅读(171) 评论(0) 推荐(0) 编辑
摘要:You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?矩阵的旋转如1 2 34 5 67 8... 阅读全文
posted @ 2014-06-29 16:34 OpenSoucre 阅读(165) 评论(0) 推荐(0) 编辑
摘要:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-nega... 阅读全文
posted @ 2014-06-29 16:14 OpenSoucre 阅读(125) 评论(0) 推荐(0) 编辑
摘要:Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word doe... 阅读全文
posted @ 2014-06-29 15:21 OpenSoucre 阅读(174) 评论(0) 推荐(0) 编辑
摘要:本题就是求所有连续子数列的和开始拿到题目还以为求的时数列子集的和,认真看到题目才知道是连续子数列循环遍历即可 int findSum(vector array) { int sum = 0; for(int i = 0 ; i < array.size(); ++... 阅读全文
posted @ 2014-06-29 14:47 OpenSoucre 阅读(185) 评论(0) 推荐(0) 编辑
摘要:典型的条件概率题目。事件A在另外一个事件B已经发生条件下的发生概率。条件概率表示为P(A|B),读作“在B条件下A的概率”。若只有两个事件A,B,那么,P(A|B)=P(AB)/P(B)本题的设事件Alice赢为B,事件Alice投掷数字x为A,则事件Alice投掷数字x且赢为AB则求在Alice赢... 阅读全文
posted @ 2014-06-29 14:44 OpenSoucre 阅读(200) 评论(0) 推荐(0) 编辑
摘要:Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histog... 阅读全文
posted @ 2014-06-26 23:57 OpenSoucre 阅读(198) 评论(0) 推荐(0) 编辑
摘要:Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A s... 阅读全文
posted @ 2014-06-26 22:55 OpenSoucre 阅读(185) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest le... 阅读全文
posted @ 2014-06-26 22:16 OpenSoucre 阅读(148) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth... 阅读全文
posted @ 2014-06-26 21:43 OpenSoucre 阅读(145) 评论(0) 推荐(0) 编辑
摘要:【转载】【啊哈!算法】系列8:巧妙的邻接表(数组实现) http://www.cnblogs.com/ahalei/p/3651334.html 之前我们介绍过图的邻接矩阵存储法,它的空间和时间复杂度都是N2,现在我来介绍另外一种存储图的方法:邻接表,这样空间和时间复杂度就都是M。对于稀疏图来说... 阅读全文
posted @ 2014-06-26 17:56 OpenSoucre 阅读(221) 评论(0) 推荐(0) 编辑
摘要:第一节 镖局运镖-图的最小生成树所谓最小生成树,就是在一个具有N个顶点的带权连通图G中,如果存在某个子图G',其包含了图G中的所有顶点和一部分边,且不形成回路,并且子图G'的各边权值之和最小,则称G'为图G的最小生成树。最小生成树的三个性质最小生成树不能有回路最小生成树可能是一个,也可能有多个最小... 阅读全文
posted @ 2014-06-26 16:11 OpenSoucre 阅读(552) 评论(0) 推荐(0) 编辑
摘要:第3节 堆排序把n个元素建立一个堆,首先将这n个结点以自顶向下、从左到右的方式从1到n编码,这样可以把n个结点转换成一颗完全二叉树紧接着从最后一个非叶子结点(结点编号为n/2)开始到根节点(结点编号为1),逐个扫描所有结点,根据需要将当前结点向下调整,直到以当前结点为根结点的子树符合堆的特性。#in... 阅读全文
posted @ 2014-06-26 12:53 OpenSoucre 阅读(281) 评论(0) 推荐(0) 编辑
摘要:Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from l... 阅读全文
posted @ 2014-06-26 00:23 OpenSoucre 阅读(188) 评论(0) 推荐(0) 编辑
摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[−2,1,−3,4,−1,2,1,... 阅读全文
posted @ 2014-06-25 23:38 OpenSoucre 阅读(112) 评论(0) 推荐(0) 编辑
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.时间复杂度O(n^3),最大全1子矩阵,利用直方图求解,可以参考对... 阅读全文
posted @ 2014-06-25 23:10 OpenSoucre 阅读(139) 评论(0) 推荐(0) 编辑
摘要:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Each number ... 阅读全文
posted @ 2014-06-25 22:10 OpenSoucre 阅读(167) 评论(0) 推荐(0) 编辑
摘要:Given a set of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Thesamerepeated num... 阅读全文
posted @ 2014-06-25 21:58 OpenSoucre 阅读(145) 评论(0) 推荐(0) 编辑
摘要:Given an integern, generate a square matrix filled with elements from 1 ton2in spiral order.For example,Givenn=3,You should return the following matri... 阅读全文
posted @ 2014-06-25 21:40 OpenSoucre 阅读(146) 评论(0) 推荐(0) 编辑
摘要:Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".class Solution {public: string addBinary(str... 阅读全文
posted @ 2014-06-25 21:07 OpenSoucre 阅读(164) 评论(0) 推荐(0) 编辑
摘要:题目的意思是给一个01的字符串数组,让你去求解满足棋盘条件的最大棋盘棋盘的条件是: 相邻元素的值不能相同此题有点像求全1的最大子矩阵,当时求全1的最大子矩阵是用直方图求解的本题可以利用直方图求解首先找到子矩阵的两个顶点坐标(x0,y0),(x1,y1)我们能遍历开始和结束列,y0=i, y1=j,... 阅读全文
posted @ 2014-06-25 18:44 OpenSoucre 阅读(249) 评论(0) 推荐(0) 编辑
摘要:题目的意思是给你一组数,然后不断的进行除法(注意是大数除以小数),然后将得到的结果加入这组数种然后继续进行除法,直到没有新添加的数为止此题按照提议模拟即可注意要保持元素的不同 int CountNumbers(vector numbers) { set ss(numbers.b... 阅读全文
posted @ 2014-06-25 16:44 OpenSoucre 阅读(200) 评论(0) 推荐(0) 编辑
摘要:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"tw... 阅读全文
posted @ 2014-06-24 22:41 OpenSoucre 阅读(138) 评论(0) 推荐(0) 编辑
摘要:Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct ... 阅读全文
posted @ 2014-06-24 22:21 OpenSoucre 阅读(146) 评论(0) 推荐(0) 编辑
摘要:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephon... 阅读全文
posted @ 2014-06-24 21:51 OpenSoucre 阅读(161) 评论(0) 推荐(0) 编辑
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a... 阅读全文
posted @ 2014-06-24 20:35 OpenSoucre 阅读(95) 评论(0) 推荐(0) 编辑
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie... 阅读全文
posted @ 2014-06-24 20:13 OpenSoucre 阅读(150) 评论(0) 推荐(0) 编辑
摘要:第一节 Floyd-Warshall算法本算法可以求任意两个点之间的最短路径,又称“多源最短路径”,其时间复杂度为O(n^3)其核心部分只有下面几行,注意加法的溢出处理 //floyd最短路径算法的核心部分 for(int k = 0; k grid[i][k]+grid[k][j])... 阅读全文
posted @ 2014-06-24 11:38 OpenSoucre 阅读(352) 评论(0) 推荐(0) 编辑
摘要:Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.先算出链表... 阅读全文
posted @ 2014-06-23 20:56 OpenSoucre 阅读(125) 评论(0) 推荐(0) 编辑
摘要:Implement strStr().Returns a pointer to the first occurrence of needle in haystack, ornullif needle is not part of haystack.class Solution {public: ... 阅读全文
posted @ 2014-06-23 20:20 OpenSoucre 阅读(141) 评论(0) 推荐(0) 编辑
摘要:Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given"25525511135",return["255.2... 阅读全文
posted @ 2014-06-23 18:14 OpenSoucre 阅读(127) 评论(0) 推荐(0) 编辑
摘要:Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No... 阅读全文
posted @ 2014-06-23 17:16 OpenSoucre 阅读(134) 评论(0) 推荐(0) 编辑
摘要:Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal... 阅读全文
posted @ 2014-06-23 17:02 OpenSoucre 阅读(107) 评论(0) 推荐(0) 编辑
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.TreeNode *createSearchTree(ListNode *&hea... 阅读全文
posted @ 2014-06-23 16:06 OpenSoucre 阅读(159) 评论(0) 推荐(0) 编辑
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.TreeNode *createSearchTree(vector& num, int left , in... 阅读全文
posted @ 2014-06-23 15:26 OpenSoucre 阅读(144) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only n... 阅读全文
posted @ 2014-06-23 14:48 OpenSoucre 阅读(117) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For exa... 阅读全文
posted @ 2014-06-23 14:11 OpenSoucre 阅读(123) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and al... 阅读全文
posted @ 2014-06-23 14:06 OpenSoucre 阅读(148) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2... 阅读全文
posted @ 2014-06-23 13:55 OpenSoucre 阅读(156) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ ... 阅读全文
posted @ 2014-06-23 12:25 OpenSoucre 阅读(137) 评论(0) 推荐(0) 编辑
摘要:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical an... 阅读全文
posted @ 2014-06-23 12:19 OpenSoucre 阅读(101) 评论(0) 推荐(0) 编辑
摘要:A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point ... 阅读全文
posted @ 2014-06-23 12:03 OpenSoucre 阅读(124) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointe... 阅读全文
posted @ 2014-06-23 00:22 OpenSoucre 阅读(167) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le... 阅读全文
posted @ 2014-06-22 23:21 OpenSoucre 阅读(127) 评论(0) 推荐(0) 编辑
摘要:Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:Yo... 阅读全文
posted @ 2014-06-22 22:49 OpenSoucre 阅读(432) 评论(0) 推荐(0) 编辑
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.简单的链表合并题L... 阅读全文
posted @ 2014-06-22 22:25 OpenSoucre 阅读(126) 评论(0) 推荐(0) 编辑
摘要:You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb... 阅读全文
posted @ 2014-06-22 22:14 OpenSoucre 阅读(124) 评论(0) 推荐(0) 编辑
摘要:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the fol... 阅读全文
posted @ 2014-06-22 21:35 OpenSoucre 阅读(296) 评论(0) 推荐(0) 编辑
摘要:Given an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].Note:Could you optimize your algorithm to use onlyO(... 阅读全文
posted @ 2014-06-22 20:28 OpenSoucre 阅读(505) 评论(0) 推荐(0) 编辑
摘要:GivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]... 阅读全文
posted @ 2014-06-22 20:01 OpenSoucre 阅读(124) 评论(0) 推荐(0) 编辑
摘要:第5节 宝岛探险利用广度优先搜索实现其中可以不用开辟visit变量,直接用将本身的值改为-1,然后判断即可注意输入数据时周围加了一层-1,作为边界广度优先搜索利用深度优先搜索实现,注意下面的方法是将搜索到的点着成-1的颜色深度优先搜索注意如果n和m比较大的话,建议用广度优先搜索,由于深度优先搜索,一... 阅读全文
posted @ 2014-06-22 15:44 OpenSoucre 阅读(441) 评论(0) 推荐(0) 编辑
摘要:Given a set of distinct integers,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not co... 阅读全文
posted @ 2014-06-21 22:17 OpenSoucre 阅读(167) 评论(0) 推荐(0) 编辑
摘要:Given two integersnandk, return all possible combinations ofknumbers out of 1 ...n.For example,Ifn= 4 andk= 2, a solution is:[ [2,4], [3,4], [2,3],... 阅读全文
posted @ 2014-06-21 18:24 OpenSoucre 阅读(131) 评论(0) 推荐(0) 编辑
摘要:Follow up for "Remove Duplicates":What if duplicates are allowed at mosttwice?For example,Given sorted array A =[1,1,1,2,2,3],Your function should ret... 阅读全文
posted @ 2014-06-21 17:46 OpenSoucre 阅读(163) 评论(0) 推荐(0) 编辑
摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3-... 阅读全文
posted @ 2014-06-21 16:54 OpenSoucre 阅读(157) 评论(0) 推荐(0) 编辑
摘要:Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, retu... 阅读全文
posted @ 2014-06-21 16:34 OpenSoucre 阅读(136) 评论(0) 推荐(0) 编辑
摘要:由于题目数据量比较小,故可以开辟一个数组存储每个index出现的次数然后遍历即可string canItBeDone(int k, vector A){ vector cnt(52,0); int n = A.size(); for(int i = 0 ; i A) { ... 阅读全文
posted @ 2014-06-20 21:30 OpenSoucre 阅读(190) 评论(0) 推荐(0) 编辑
摘要:关于证明可以参考题解http://codeforces.com/blog/entry/12739就是将概率从大到小排序然后,然后从大到小计算概率#include #include #include #include #include #include using namespace std;int ... 阅读全文
posted @ 2014-06-20 20:44 OpenSoucre 阅读(167) 评论(0) 推荐(0) 编辑
摘要:本题要考虑字符串本身就存在tandem,如测试用例aaaaaaaaabbb3输出结果应该是8而不是6,因为字符串本身的tanderm时最长的故要考虑字符串本身的最大的tanderm和添加k个字符后最大的tanderm#include #include #include #include #inclu... 阅读全文
posted @ 2014-06-20 17:15 OpenSoucre 阅读(324) 评论(0) 推荐(0) 编辑
摘要:题目很简单,只需要注意带空格的输入用getline即可#include #include #include #include #include using namespace std;int main(){ string str; getline(cin,str); set a; ... 阅读全文
posted @ 2014-06-20 17:11 OpenSoucre 阅读(135) 评论(0) 推荐(0) 编辑
摘要:由于题目告诉肯定至少存在一种解,故只需要根据条件遍历一下, vector makeExpression(int y) { vector res; for(int i = -1000; i =-1000 && k<=1000 && k!=0 && k!=1){ ... 阅读全文
posted @ 2014-06-19 21:11 OpenSoucre 阅读(144) 评论(0) 推荐(0) 编辑
摘要:Given a 2D board containing'X'and'O', capture all regions surrounded by'X'.A region is captured by flipping all'O's into'X's in that surrounded region... 阅读全文
posted @ 2014-06-19 17:17 OpenSoucre 阅读(130) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which rep... 阅读全文
posted @ 2014-06-19 15:45 OpenSoucre 阅读(150) 评论(0) 推荐(0) 编辑
摘要:There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costscost[... 阅读全文
posted @ 2014-06-19 15:10 OpenSoucre 阅读(262) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].No... 阅读全文
posted @ 2014-06-18 22:50 OpenSoucre 阅读(136) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Not... 阅读全文
posted @ 2014-06-18 22:25 OpenSoucre 阅读(124) 评论(0) 推荐(0) 编辑
摘要:Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.For exampl... 阅读全文
posted @ 2014-06-18 21:18 OpenSoucre 阅读(167) 评论(0) 推荐(0) 编辑
摘要:Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For exam... 阅读全文
posted @ 2014-06-18 19:45 OpenSoucre 阅读(111) 评论(0) 推荐(0) 编辑
摘要:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the valu... 阅读全文
posted @ 2014-06-18 17:15 OpenSoucre 阅读(157) 评论(0) 推荐(0) 编辑
摘要:Sort a linked list using insertion sort.单链表的插入排序, 考查的时单链表指针的断开和插入操作#include #include #include using namespace std;struct ListNode{ int val; List... 阅读全文
posted @ 2014-06-18 16:48 OpenSoucre 阅读(117) 评论(0) 推荐(0) 编辑
摘要:Sort a linked list inO(nlogn) time using constant space complexity.本题利用归并排序即可归并排序的核心是将两部分合成一部分,故开始要将链表分成两部分,利用快慢两个指针,当快指针跑到链表尾部时,慢指针恰好在中间,故可以将链表分成两部分然... 阅读全文
posted @ 2014-06-18 16:16 OpenSoucre 阅读(159) 评论(0) 推荐(0) 编辑
摘要:Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.此题是求直线上点最多的点数,根据两点构成一条直线,在同一条直线上,任意两点之间的斜率都相同,故需要对每个点... 阅读全文
posted @ 2014-06-18 14:31 OpenSoucre 阅读(145) 评论(0) 推荐(0) 编辑
摘要:Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another express... 阅读全文
posted @ 2014-06-18 12:32 OpenSoucre 阅读(138) 评论(0) 推荐(0) 编辑
摘要:Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".此题要注意的几个情况是:(1)输入字符串可能含有前缀0和后缀... 阅读全文
posted @ 2014-06-18 11:17 OpenSoucre 阅读(115) 评论(0) 推荐(0) 编辑
摘要:注意题目给的最后一句话,如果部门任何employee都做不同类型的工作,则这个部门是一个diverse,题目是计算department的diverse数读起来感觉有点别扭,英语没学好的原因 int countGood(vector superior, vector workType) { ... 阅读全文
posted @ 2014-06-16 21:28 OpenSoucre 阅读(200) 评论(0) 推荐(0) 编辑
摘要:一开始Y1,Y2两个参数看不懂,再看一遍题目后才知道,vector索引代表是行数,值代表的是列此题数据量不大,直接深度搜索即可注意这里深度搜索的访问标识不是以前的索引和元素,而是一个交换元素后的整个状态vector,这样可以避免重复元素的搜索 set > visit; bool flag... 阅读全文
posted @ 2014-06-16 20:35 OpenSoucre 阅读(176) 评论(0) 推荐(0) 编辑
摘要:只需要对word遍历一遍即可 int write(string word) { int cnt = 0; for(int i = 0 ; i < word.length(); ++ i){ cnt+=word[i]-'A'+1; ... 阅读全文
posted @ 2014-06-16 20:01 OpenSoucre 阅读(135) 评论(0) 推荐(0) 编辑
摘要:此题给出的条件是:(1)word的每个字母都是大写字母(此条件可以忽略,题目给的输入都是大写字母)(2) 相等字符不能连续,即不能出现AABC的连续相同的情况(3)word中不存在字母组成xyxy的形式,即不存在第一个字符和第3个字符相等同时第2个字符和第4个字符相等的情况对于第(2)种情况,只需要... 阅读全文
posted @ 2014-06-16 20:00 OpenSoucre 阅读(264) 评论(0) 推荐(0) 编辑
摘要:说明自己的8086端口被占用了运行:lsof -i:8086然后kill掉对应的PID 阅读全文
posted @ 2014-06-15 19:39 OpenSoucre 阅读(8) 评论(0) 推荐(0) 编辑
摘要:此题用贪心求解,首先将caramel drop类别的糖果按照高度从小到大排序,如果高度相同,按照重量从小到大排序将fruit drop类别的糖果按照高度从小到大排序,如果高度相同,按照重量从小到大排序现在有两种可能第一种可能是第一个获得的糖果是caramel drop,则先搜索caramel dro... 阅读全文
posted @ 2014-06-14 23:56 OpenSoucre 阅读(298) 评论(0) 推荐(0) 编辑
摘要:注意题目给的是一个nxm的park,设元素为aij,元素aij 有4种可能U(上移),D(下移),L(左移),R(右移)假设第i行第j列元素aij(注意元素的索引是从0开始的)当aij为D时,此时spiders一直往下移动不可能与Om Nom相遇当aij为U时,此时spiders向上移动时此时Nor... 阅读全文
posted @ 2014-06-14 20:52 OpenSoucre 阅读(290) 评论(0) 推荐(0) 编辑
摘要:暴利搜索即可#include #include #include using namespace std;int main(){ int n,k,x; cin >> n >> k >> x; vector c(n); for(int i = 0 ; i > c[i]; ... 阅读全文
posted @ 2014-06-13 21:05 OpenSoucre 阅读(181) 评论(0) 推荐(0) 编辑
摘要:水到家了#include #include #include using namespace std;struct Point{ int index, pos; Point(int index_ = 0, int pos_ = 0){ index = index_; ... 阅读全文
posted @ 2014-06-13 18:30 OpenSoucre 阅读(145) 评论(0) 推荐(0) 编辑
摘要:模拟即可#include #include #include using namespace std;int main(){ vector a(5); for(int i = 0; i > g[i][j]; } } int maxHappiness = 0; ... 阅读全文
posted @ 2014-06-13 17:53 OpenSoucre 阅读(237) 评论(0) 推荐(0) 编辑
摘要:水题#include #include #include using namespace std;int main(){ vector a(4); cin >> a[0] >> a[1]>>a[2]>>a[3]; string str; cin >> str; int res = 0; for(in... 阅读全文
posted @ 2014-06-13 17:25 OpenSoucre 阅读(151) 评论(0) 推荐(0) 编辑
摘要:看到题目的时候,以为类似插入排序,比较第i个元素和第i-1个元素,如果第i个元素比第i-1个元素小,则不交换如果第i个元素比第i-1个元素大,则交换第i个元素和第i-1个元素 继续比较第i-1个元素与前一个元素,直到前一个元素大为止交换元素次大于等于k则停止但对测试用例1234 3则出现问题,如果... 阅读全文
posted @ 2014-06-13 17:14 OpenSoucre 阅读(190) 评论(0) 推荐(0) 编辑
摘要:从大到小遍历一遍,每次取M个元素,然后求得最小的floor即可 int minimum(int M, vector heights) { sort(heights.begin(),heights.end()); int minFloor = 10000; ... 阅读全文
posted @ 2014-06-13 11:19 OpenSoucre 阅读(171) 评论(0) 推荐(0) 编辑
摘要:排个序,求前k个元素和即可 int minimum(int K, vector danceCost) { sort(danceCost.begin(),danceCost.end()); return accumulate(danceCost.begin()... 阅读全文
posted @ 2014-06-13 11:05 OpenSoucre 阅读(118) 评论(0) 推荐(0) 编辑
摘要:screen 尺寸为a:bvideo 尺寸为 c:d如果a == c 则 面积比为 cd/ab=ad/cb (ad c/d,则ad/bd > cb/db 则(ad > cb) screen尺寸可为 ad:bd, video的尺寸可为 cb:db 面积比为:cb*db/ad*bd = cb/ad... 阅读全文
posted @ 2014-06-12 20:28 OpenSoucre 阅读(157) 评论(0) 推荐(0) 编辑
摘要:水题,注意数据范围即可#include #include #include using namespace std;typedef pair Point;int main(){ int x,y; cin >> x >>y; Point a,b; if((x>0 && y > ... 阅读全文
posted @ 2014-06-12 11:28 OpenSoucre 阅读(132) 评论(0) 推荐(0) 编辑
摘要:1、stl源码2、jsoncpp源码3、Leveldb源码 阅读全文
posted @ 2014-06-11 23:58 OpenSoucre 阅读(156) 评论(0) 推荐(0) 编辑
摘要:第一种方法参考论文《视频跟踪中得背景建模》 在进行孔洞填充时,对像素(x,y)周围的八连通区域进行判断,具体步骤为: (1)首先将原图拷贝到缓存中,然后用以待填充的像素点(x,y)为中心的3x3的块对整幅图像进行扫描,并用计数器记录下这个块所覆盖的9个点中,灰度值为255的点的个数 (2)对计数器N... 阅读全文
posted @ 2014-06-11 22:22 OpenSoucre 阅读(4637) 评论(0) 推荐(0) 编辑
摘要:此题需要注意的两个地方是(1)在某天生产出来的Slimonades,必须在stale_limit天内必须卖完,否则超过stale_limit内抛弃(东西都有保质期)(2)每天生产出来的Slimonades的数量在0到morning[i]之间,而不是morning[i]故第i天卖的东西可能来自max(... 阅读全文
posted @ 2014-06-10 23:23 OpenSoucre 阅读(129) 评论(0) 推荐(0) 编辑
摘要:水题#include #include #include using namespace std;int main(){ int n,m; cin >> n >> m; int cnt = 0, sum = 0; for(int i = 0 ; i > a; i... 阅读全文
posted @ 2014-06-10 12:10 OpenSoucre 阅读(127) 评论(0) 推荐(0) 编辑
摘要:注意题目长度不能考虑前缀,而且如果即存在一个选项的长度的两倍小于其他所有选项的长度,也存在一个选项的长度大于其他选项长度的两倍,则答案不是一个好的选择,只能选择C。#include #include #include #include using namespace std;struct Answe... 阅读全文
posted @ 2014-06-10 11:40 OpenSoucre 阅读(167) 评论(0) 推荐(0) 编辑
摘要:注意此题,每一个部分都有一个能量值v[i],他移除第i部分所需的能量是v[f[1]]+v[f[2]]+...+v[f[k]],其中f[1],f[2],...,f[k]是与i直接相连(且还未被移除)的部分的编号。注意题目移除的都是与第i部分直接相连的部分的能量值,将本题目简化得,只考虑两个点1和2,1... 阅读全文
posted @ 2014-06-10 11:31 OpenSoucre 阅读(135) 评论(0) 推荐(0) 编辑
摘要:水题,只要遍历一遍,不够平均数的,从后面的借,比平均数多的,把多余的数添加到后面即可,注意数据范围#include #include #include using namespace std;int main(){ int n; cin >> n; vector a(n); ... 阅读全文
posted @ 2014-06-09 22:36 OpenSoucre 阅读(146) 评论(0) 推荐(0) 编辑
摘要:水题,注意数据范围#include using namespace std;int main(){ long long n,a; cin >> n; long long sum =(n*(n+1))>>1; for(int i = 0 ; i >a; sum ... 阅读全文
posted @ 2014-06-09 22:34 OpenSoucre 阅读(152) 评论(0) 推荐(0) 编辑
摘要:贪心算法,每条路径最短2格,故前k-1步每次走2格,最后一步全走完由于数据比较小,可以先打表#include #include #include #include using namespace std;typedef pair Point;int main(){ int n, m, k, f... 阅读全文
posted @ 2014-06-09 21:04 OpenSoucre 阅读(213) 评论(0) 推荐(0) 编辑
摘要:#include #include #include #include using namespace std;int main(){ int n,v; cin >> n >>v; map fruit; for(int i = 0 ; i >a >> b; if... 阅读全文
posted @ 2014-06-09 19:53 OpenSoucre 阅读(203) 评论(0) 推荐(0) 编辑
摘要:水题#include #include #include #include using namespace std;int main(){ int n,v; cin >> n >> v; vector res; for(int i = 0; i > k; for... 阅读全文
posted @ 2014-06-09 19:02 OpenSoucre 阅读(368) 评论(0) 推荐(0) 编辑
摘要:注意p的边界情况,p为0,或者 p为k奇数+偶数 = 奇数奇数+奇数 = 偶数#include #include #include #include #include using namespace std;int main(){ int n,k,p; long a; cin >>... 阅读全文
posted @ 2014-06-09 00:59 OpenSoucre 阅读(211) 评论(0) 推荐(0) 编辑
摘要:注意数据范围即可#include #include #include using namespace std;int main(){ long long n,x; cin >> n >> x; vector c(n); for(int i = 0 ; i > c[i]; ... 阅读全文
posted @ 2014-06-08 22:59 OpenSoucre 阅读(201) 评论(0) 推荐(0) 编辑
摘要:水题#include #include #include using namespace std;int main(){ int n,d,t; cin >> n >> d; for(int i = 0 ; i > t; d-=t; } d-=(n-1)*1... 阅读全文
posted @ 2014-06-08 22:35 OpenSoucre 阅读(209) 评论(0) 推荐(0) 编辑
摘要:解决本题的一个关键点就是当Cat进入时,此时Rat在哪个位置?注意移动方向可以随时改变,由于是圆环,故离入口最远点的距离是pi*R,即圆的一半,当cat进入时(cat的速度大于rat的速度,否则不可能追上) 如果rat移动的距离小于圆环的一半,即此时rat的位置为移动最远的位置 如果rat移动的... 阅读全文
posted @ 2014-06-05 21:47 OpenSoucre 阅读(240) 评论(0) 推荐(0) 编辑
摘要:比较简单的一题,纠结比较久的是把my_cmp和my_minus放在类中,利用sort函数会出现no matching function for call to ""sort(std::vector::iterator, std::vector::iterator, )""当把这两个函数放在类外面时就... 阅读全文
posted @ 2014-06-05 20:53 OpenSoucre 阅读(191) 评论(0) 推荐(0) 编辑
摘要:关于斐波那契数列,由于数据量比较小, 直接打表了,代码写的比较戳#include #include #include using namespace std;class FibonacciDiv2{public: vector table; void make_table(){ ... 阅读全文
posted @ 2014-06-04 00:23 OpenSoucre 阅读(311) 评论(0) 推荐(0) 编辑
摘要:注意题目这句话,Once you have each type of candies in a box, you want to pack those boxes into larger boxes, until only one box remains.两个box合并后必须放入更大一个盒子题目的有... 阅读全文
posted @ 2014-06-04 00:20 OpenSoucre 阅读(215) 评论(0) 推荐(0) 编辑
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?借用博... 阅读全文
posted @ 2014-06-02 00:21 OpenSoucre 阅读(148) 评论(0) 推荐(0) 编辑
摘要:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?求链表是否有环的问题,要考虑链表为空的情况,定义一个快指针和一个慢指针,如果快指针和... 阅读全文
posted @ 2014-06-01 23:33 OpenSoucre 阅读(198) 评论(0) 推荐(0) 编辑
摘要:Search Insert PositionTotal Accepted:15484Total Submissions:44816Given a sorted array and a target value, return the index if the target is found. If ... 阅读全文
posted @ 2014-06-01 22:30 OpenSoucre 阅读(279) 评论(0) 推荐(0) 编辑

喜欢请打赏

扫描二维码打赏

了解更多

点击右上角即可分享
微信分享提示