自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(52)
  • 收藏
  • 关注

原创 对Pollard's Rho算法的理解

对于一个一般来说我们可以通过试探

2014-07-17 22:15:00 4346 2

原创 灰太狼抓羊

题目详情:    羊村新建了许多地下房子,这些地下房子的分布成树状结构。每一个房子有一个编号,从0—n-1,0号是村长的房子。注意每间房子只住着一只羊。村长的房子是其他所有房子的入口(即根节点),之后每个房子最多通向其他两个房子。房子与房子之间有不同的距离。  灰太狼听从他老婆的命令,去抓羊。灰太狼总是每秒前行1米,这导致他有时候不能完成他老婆给他的任务。他老婆会有很多

2014-04-29 16:39:53 1646

原创 正整数异或值问题

题目详情:给你n个正整数,请你计算出有多少对数的异或值小于等于k。输入描述:输入包含多组测试数据,每组测试数据包含两行,第一行为两个正整数n(2输出描述:对于每组测试数据输出相应的答案。答题说明:输入样例:5 64 3 5 7 95 37 9 8 4 3输出样例:52

2014-04-29 13:00:20 1316

原创 [Code Jam] Bribe the Prisoners

ProblemIn a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. Cells number i and i+1 are adjacent, and prisoners in adjacent cells are called "neighbours." A

2014-04-28 20:11:37 774

原创 A^B = B^A

题目详情:求解 A^B = B^A, (A!=B) ^表示乘方输入格式多组数据,每组数据一行,有一个不小于1.1的浮点数,表示A和B中比较小的,求另外一个数。输出格式每组数据一行,如果有解输出解,保留5位小数,否则输出-1。答题说明:输入样例  210输出样例  4.00000

2014-04-27 13:30:59 827 2

原创 [Code Jam] Millionaire

Problem C. MillionaireThis contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start Gui

2014-04-27 11:08:16 584

原创 [Code Jam] Crazy Rows

ProblemYou 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 the matrix below or on the main diagonal. That i

2014-04-27 10:02:00 580

原创 最大的划分

题目详情:有一排高度依次为H1,H2,H3,....,Hn的树木,一共n棵树,如果某棵树(不含两端的树)比相邻的两棵树都要高,则这样的树就称为景点树,现在管理员要将这n棵树划分成连续等长的部分进行管理,并且每部分之中至少含有一棵景点树。管理员希望划分的部分个数最大,你能帮助他吗?输入描述:有多组测数数据,每组数据有两行,第一行包含一个正整数n(0输入以文件结束。

2014-04-26 23:43:15 910 2

原创 最大角度

题目详情:给定平面上若干个点,两个人玩游戏,第一个人选取一个点A,另外一个人选取另外两个不同的点B,C,与A连线可以形成一个角BAC,第一个人希望这个角越大越好,第二个人希望这个角越小越好。两个人都足够聪明,请问最后这个角有多大?输入格式多组数据,每组数据第一行是一个正整数n (3输出格式输出一个实数,表示最终可以得到的角度值,保留4位小数(第5位四舍五

2014-04-26 08:31:12 1111 1

原创 拓展欧几里得算法

感觉自己搞懂这个算法了,记录一下。

2014-04-25 10:40:07 613 2

原创 HDOJ 1074-Doing Homework

之前见到这道题时没像出来怎么写,今天在网上搜了一下,发现了一个名词-状态压缩的动态规划。在这个题里的状态压缩的表现形式就是用二进制表示已选集合,这样做就可以用动态规划来解这种解空间为排序树的题了,之前见过几道这种题,都卡在如何表示已选集合上面。收获不小。#includeint dp[1 << 16], end[1 << 16], back[1 << 16];int d[16], c[16];

2014-04-22 19:58:46 536

原创 3Sum

Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c

2014-04-19 13:12:45 416

原创 蚂蚁感冒

问题描述  长100厘米的细长直杆子上有n只蚂蚁。它们的头有的朝左,有的朝右。  每只蚂蚁都只能沿着杆子向前爬,速度是1厘米/秒。  当两只蚂蚁碰面时,它们会同时掉头往相反的方向爬行。  这些蚂蚁中,有1只蚂蚁感冒了。并且在和其它蚂蚁碰面时,会把感冒传染给碰到的蚂蚁。  请你计算,当所有蚂蚁都爬离杆子时,有多少只蚂蚁患上了感冒。输入格式  第

2014-04-19 11:18:17 910

原创 3Sum Closest

Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact

2014-04-18 22:23:43 425

原创 求数列的下一个排列

class Solution {bool check(vector num){for(int i = 0; i {if(num[i] {return true;}}return false;}void adj(vector &num){int i = num.size() - 1;while(num[i - 1] >= num[i])

2014-04-18 22:09:06 526

原创 Minimum Window Substring

Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BAN

2014-04-14 14:13:33 462

原创 烟花效果

今天最后尝试了一下一直以来都

2014-04-13 23:14:41 673

原创 心形函数-封心

这个是《html5实验室-Canvas世界》中的一个例子,最大的收获当然是心形

2014-04-13 17:20:46 14451

原创 风车——ctx.rotate(angle),ctx.translate(dx, dy)

以前见过这样的动画,

2014-04-13 14:28:11 2704

原创 getImageData(ox, oy, width, height)

在《html5实验室-Canvas世界》中,看到了一个

2014-04-13 10:22:32 704

原创 地宫取宝

问题描述  X 国王有一个地宫宝库。是 n x m 个格子的矩阵。每个格子放一件宝贝。每个宝贝贴着价值标签。  地宫的入口在左上角,出口在右下角。  小明被带到地宫的入口,国王要求他只能向右或向下行走。  走过某个格子时,如果那个格子中的宝贝价值比小明手中任意宝贝价值都大,小明就可以拿起它(当然,也可以不拿)。  当小明走到出口时,如果他手中的宝贝恰好是k件

2014-04-09 09:22:37 957

原创 asp.net学习笔记

这几天学asp.net,之前一直以为

2014-04-08 19:15:02 393

原创 <<javascript 高效图形编程>>笔记

某天在学校图书馆里溜达的时候看见的这本书,感觉应该有点干货就借回来了.放了几天,今天干什么都不对劲,就把这本书拿出来看了看,发现一些有意思的东西.第一个是一个递归绘图,之前见过类似的小动画,感觉很神奇,没想到在这本书里的代码就简简单单的一点.对我来说最没想到的是这个代码就像平时的递归程序一样简单,我总觉得牵涉到图形的时候一切都悔变得复杂,就不愿意动脑了,这样不好.

2014-04-02 23:39:14 552

原创 翻纸牌游戏

题目详情:题目描述有一种纸牌游戏,很有意思,给你N张纸牌,一字排开,纸牌有正反两面,开始的纸牌可能是一种乱的状态(有些朝正,有些朝反),现在你需要整理这些纸牌。但是麻烦的是,每当你翻一张纸牌(由正翻到反,或者有反翻到正)时,他左右两张纸牌(最左边和最右边的纸牌,只会影响附近一张)也必须跟着翻动,现在给你一个乱的状态,问你能否把他们整理好,使得每张纸牌都正面朝上,如果可以,最少需

2014-04-01 23:25:14 1455

原创 Populating Next Right Pointers in Each Node I & II

Populating Next Right Pointers in Each Node Total Accepted: 10797 Total Submissions: 31598My SubmissionsGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; Tre

2014-03-26 16:47:37 536

原创 送礼物

题目详情HeHe和XiXi在一个地方玩游戏,XiXi把N-1件礼物(HeHe以前送给XiXi的)分别藏在了另外N-1个地方,这些地方都能互相到达,且所有的边都是有方向的。现在HeHe要做的事就是去那些地方找回那N-1件礼物给XiXi;由于每一件礼物都有特殊的意义,所以XiXi要求HeHe每找到一件礼物,就必须马上返回XiXi所在的位置,对她说一句当年送她这件礼物的时候所

2014-03-24 23:26:25 631

原创 Sum Root to Leaf Numbers

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the tota

2014-03-20 20:14:29 442

原创 Search in Rotated Sorted Array

Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array retur

2014-03-17 22:45:16 430

原创 Single Number I & II

Single NumberGiven an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement i

2014-03-16 10:23:01 421

原创 ZigZag Conversion

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I

2014-03-15 16:23:29 433

原创 Median of Two Sorted Arrays

There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).这也算是一道经典题目了吧。背景应该是并归排序。class Solu

2014-03-14 23:54:44 420

原创 Two Sum

Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, whe

2014-03-14 23:23:25 439

原创 Path Sum

Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum

2014-03-13 15:16:38 427

原创 Binary Tree Maximum Path Sum

Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return 6.

2014-03-12 19:35:03 419

原创 Decode Ways

A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu

2014-03-11 15:16:45 525

原创 Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo

2014-03-10 15:05:53 490

原创 子序列的个数

题目详情本题同样来自caopengcs,只要你有兴趣,每个人都可以出题(出题入口在主页右侧边栏“贡献题目”->“我要发布”内),以下是题目详情:子序列的定义:对于一个序列a=a[1],a[2],......a[n],则非空序列a'=a[p1],a[p2]......a[pm]为a的一个子序列,其中1例如:4,14,2,3和14,1,2,3都为4,13,14,1,2,3的

2014-03-09 17:25:45 694

原创 交替字符串

题目详情如果字符串str3能够由str1和str2中的字符按顺序交替形成,那么称str3为str1和str2的交替字符串。例如str1="abc",str2="def",那么"adbecf", "abcdef", "abdecf", "abcdef", "adefbc"等等都为str1和str2的交替字符串。更形式化的,str3的生成算法如下:str3=""while

2014-03-07 22:59:44 929 4

原创 xor值最大

题目详情给定整数区间[a,b],从闭区间[a,b]中选择两个数,使得它们的异或值最大。 0这道题还把我给难住了,花了好长时间才分析出一点眉目,大概还是对数学的知觉不够,要加油!!!//一个复杂算的方法#includetypedef long long ll;ll set(ll v, int top){    ll re

2014-03-07 22:38:37 1177

原创 无穷字符串

题目详情假设字符串A=“^__^" (4个字符),B="T.T"(3个字符),我们进行如下步骤:(1) 把A接到B的后面得到字符串C (按样例C="T.T^__^")(2) 令A=B,B=C不断重复步骤(1)(2)得到的字符串是无穷的。求这个串的第n个字符。(0我看到这道题的时候它才2个通过,我差点就是第三个了,哎。问题在于我

2014-03-07 18:29:07 980 1

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除