自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(54)
  • 问答 (3)
  • 收藏
  • 关注

转载 并查集

并查集是我暑假从高手那里学到的一招,觉得真是太精妙的设计了。以前我无法解决的一类问题竟然可以用如此简单高效的方法搞定。不分享出来真是对不起party了。(party:我靠,关我嘛事啊?我跟你很熟么?)来看一个实例,杭电1232畅通工程首先在地图上给你若干个城镇,这些城镇都可以看作点,然后告诉你哪些对城镇之间是有道路直接相连的。最后要解决的是整幅图的连通性问题。比如随意给你两个点

2015-07-31 15:04:15 300

转载 最大连续子序列各种解法

1.首先最朴素的方法是暴力 O(n^3)       直接两个for循环枚举子序列的首尾,然后再来个循环计算序列的和,每次更新和的最大值。        但是这种方法的复杂度是O(n^3),效率实在太低了。。。————————————————————————————————————————————————2.第二种方法是预处理 O(n^2)     

2015-07-27 21:53:12 1238

转载 二分查找

int BinSearch(int Array[],int low,int high,int key/*要找的值*/) { if (low<=high) { int mid = (low+high)/2; if(key == Array[mid]) return mid; else

2015-07-21 20:41:58 293

转载 POJ 1019 Number Sequence

描述A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2...Sk. Each group Sk consists of a sequence of positive i

2015-07-21 12:14:21 302

转载 整数划分

描述整数划分是一个经典的问题。请写一个程序,完成以下要求。 输入每组输入是两个整数n和k。(1 输出对于输入的 n,k;第一行: 将n划分成若干正整数之和的划分数。第二行: 将n划分成k个正整数之和的划分数。第三行: 将n划分成最大数不超过k的划分数。第四行: 将n划分成若干个 奇正整数之和的划分数。第五行: 将n划分成若干不同整数之和的

2015-07-20 16:41:38 440

转载 母函数入门

母函数(Generating function)详解— Tanky Woo在数学中,某个序列的母函数(Generating function,又称生成函数)是一种形式幂级数,其每一项的系数可以提供关于这个序列的信息。使用母函数解决问题的方法称为母函数方法。母函数可分为很多种,包括普通母函数、指数母函数、L级数、贝尔级数和狄利克雷级数。对每个序列都可以写出以上每个类型的一

2015-07-20 16:13:44 370

转载 博奕

有一种很有意思的游戏,就是有物体若干堆,可以是火柴棍或是围棋子等等均可。两个人轮流从堆中取物体若干,规定最后取光物体者取胜。这是我国民间很古老的一个游戏,别看这游戏极其简单,却蕴含着深刻的数学原理。下面我们来分析一下要如何才能够取胜。(一)巴什博奕(Bash Game):只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最多取m个。最后取光者得胜。

2015-07-20 14:57:42 633

原创 马的走法

在一个4X5的棋盘上,马的起始位置坐标(纵、横)位置由键盘输入,求马能返回初始位置的所有不同走法的总数(马走过的位置不能重复,马走“日”字)。输入输入文件第一行为测试用例的个数N,接下来N行,每行两个正整数x,y(1,表示马的位置坐标.输出每个测试用例的输出占一行,输出马能返回初始位置的所有不同走法的总数,如果没有,则输出“ERROR”(不包含双引号)。

2015-07-16 16:26:16 1042

转载 C/C++申请空间与释放空间的两种方法

1.   C语言的函数malloc和free (1) 函数malloc和free在头文件中的原型及参数       void * malloc(size_t size)动态配置内存,大小有size决定,返回值成功时为任意类型指针,失败时为NULL。       void  free(void *ptr)释放动态申请的内存空间,调用free

2015-07-16 10:54:52 15694

转载 匈牙利算法

用于求最大匹配问题bool find(int x){ int i,j; for (j=1;j<=m;j++) { //扫描每个妹子 if (line[x][j]==true && used[j]==false) //如果有暧昧并且还没有标记过(这里标记的意思是这次查找曾试图改变过该妹子的归属问题,但是

2015-07-16 09:12:04 437

转载 ZOJ 1002 FZU 1098 HDU 1045 Fire Net

Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall.A blockhouse is a small castl

2015-07-15 17:00:42 410

原创 函数库的排序调用 sort qsort

两个都在C++函数库里面#includeusing namespace std;sort(a,a+n,cmp);  cmp可加可不对 对数列从某位置到某位置进行排序如果不加cmp则按小到大排 cmp是排序的条件bool cmp(int x,int y) return x>y;这里就按大到小排 传入的类型可以是各种类型 跟A数组

2015-07-15 10:15:33 479

原创 HDU 1180 诡异的楼梯

Problem DescriptionHogwarts正式开学以后,Harry发现在Hogwarts里,某些楼梯并不是静止不动的,相反,他们每隔一分钟就变动一次方向.比如下面的例子里,一开始楼梯在竖直方向,一分钟以后它移动到了水平方向,再过一分钟它又回到了竖直方向.Harry发现对他来说很难找到能使得他最快到达目的地的路线,这时Ron(Harry最好的朋友)告诉Harry正好有一个魔法

2015-07-14 16:41:37 982

原创 C++函数队列 BFS的好帮手

queue变量先进先出empty() 如果队列为空返回真pop() 删除对顶元素push() 加入一个元素size() 返回优先队列中拥有的元素个数top() 返回优先队列对顶元素优先队列  按某特定条件出列priority_queueq可以直接定义在结构体里面friend bool operator(a,b)return a.a

2015-07-14 16:11:53 449

原创 HDU 1242 Rescue

Problem DescriptionAngel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M Angel's friends want to save Angel. Their task is: approach Angel. W

2015-07-14 15:41:47 388

原创 HDU 1671 Phone List

Problem DescriptionGiven a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let’s say the phone catalogue listed these numbers:1. Emergenc

2015-07-14 15:15:28 316

原创 HDU 1075 What Are You Talking About

Problem DescriptionIgnatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leave

2015-07-14 14:40:55 313

原创 HDU 1240 Asteroids!

Problem DescriptionYou're in space.You want to get home.There are asteroids.You don't want to hit them. InputInput to this problem will consist of a (non-empty) series of up to 100 d

2015-07-14 14:39:37 451

原创 HDU 1372 Knight Moves

Problem DescriptionA friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits each square of a given set of n

2015-07-14 14:36:36 418

原创 HDU 1072 Nightmare

Problem DescriptionIgnatius had a nightmare last night. He found himself in a labyrinth with a time bomb on him. The labyrinth has an exit, Ignatius should get out of the labyrinth before the bomb e

2015-07-14 13:54:56 296

原创 HDU 1016 Prime Ring Problem

A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime.Note: the number o

2015-07-14 10:04:18 298

原创 HDU 1312 Red and Black

Problem DescriptionThere is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjace

2015-07-14 10:03:16 366

原创 HDU 1241 Oil Deposits

Problem DescriptionThe GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a

2015-07-14 10:01:41 309

原创 HDU 1181 变形课

Problem Description呃......变形课上Harry碰到了一点小麻烦,因为他并不像Hermione那样能够记住所有的咒语而随意的将一个棒球变成刺猬什么的,但是他发现了变形咒语的一个统一规律:如果咒语是以a开头b结尾的一个单词,那么它的作用就恰好是使A物体变成B物体.Harry已经将他所会的所有咒语都列成了一个表,他想让你帮忙计算一下他是否能完成老师的作业,将一个B(b

2015-07-14 10:00:25 352

转载 HDU 2102 A计划

Problem Description可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验。魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老。年迈的国王正是心急如焚,告招天下勇士来拯救公主。不过公主早已习以为常,她深信智勇的骑士LJ肯定能将她救出。现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位

2015-07-14 09:58:55 420

转载 HDU 1548 A strange lift

Total Submission(s) : 11   Accepted Submission(s) : 3Problem DescriptionThere is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 <= Ki <= N) on every fl

2015-07-14 09:54:52 339

原创 HDU 1728 逃离迷宫

给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有些地方是障碍,她必须绕行,从迷宫的一个位置,只能走到与它相邻的4个位置中,当然在行走过程中,gloria不能走到迷宫外面去。令人头痛的是,gloria是个没什么方向感的人,因此,她在行走过程中,不能转太多弯了,否则她会晕倒的。我们假定给定的

2015-07-14 09:53:29 427

原创 HDU 1239 Calling Extraterrestrial Intelligence Again

A message from humans to extraterrestrial intelligence was sent through the Arecibo radio telescope in Puerto Rico on the afternoon of Saturday November 16, 1974. The message consisted of 1679 bits an

2015-07-14 09:50:42 400

原创 HDU 1597 find the nth digit

Problem Description假设:S1 = 1S2 = 12S3 = 123S4 = 1234.........S9 = 123456789S10 = 1234567891S11 = 12345678912............S18 = 123456789123456789..................现在我们把所有的串连接起

2015-07-14 09:49:12 423

原创 HDU 1253 胜利大逃亡

Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会.魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示成A个B*C的矩阵,刚开始Ignatius被关在(0,0,0)的位置,离开城堡的门在(A-1,B-1,C-1)的位置,现在知道魔王将在T分钟后回到城堡,Ignatius每分钟能从一个坐标走到相邻的六个坐标中的其中一个.现在给你城堡的地图,请你计算

2015-07-14 09:47:42 383

原创 HDU 1015 Safecracker

=== Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Klein safe behind a painting in the second-floor library. Klein safes are extremely rare; most of them, along with Klein and h

2015-07-14 09:46:14 413

转载 HDU 1010 Tempter of the Bone

The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone

2015-07-14 09:44:44 376

原创 HDU 2124 Repair the Wall

Long time ago , Kitty lived in a small village. The air was fresh and the scenery was very beautiful. The only thing that troubled her is the typhoon.When the typhoon came, everything is terrible.

2015-07-14 09:41:08 591

原创 HDU 1257 最少拦截系统

某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹.怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统

2015-07-14 09:39:00 352

原创 HDU 1009 FatMouse' Trade

FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.The warehouse has N rooms. The i-th room contains J[i] pounds of Ja

2015-07-14 09:37:44 354

原创 HDU 1049 Climbing Worm

An inch worm is at the bottom of a well n inches deep. It has enough energy to climb u inches every minute, but then has to rest a minute before climbing again. During the rest, it slips down d inches

2015-07-14 09:35:08 378

原创 悼念512汶川大地震遇难同胞——老人是真饿了

时间:2008年5月16日(震后第4天)地点:汶川县牛脑寨人物:羌族老奶奶【转载整理】牛脑寨是一个全村600多人的羌族寨子,震后几天,这里依然能常常听到隆隆的声音,那是对面山上石头不断滑落的声音。在完成整个突击队的抢修移动基站的任务后,我提着相机开始记录这里的受创情况。突然,我的视线里出现一个羌族老人,这让我无比的震惊,要知道,那是一个极陡的坡,这个佝偻着腰的老人是怎么艰难地爬

2015-07-14 09:32:00 516

原创 HDU 2570 迷瘴

通过悬崖的yifenfei,又面临着幽谷的考验——幽谷周围瘴气弥漫,静的可怕,隐约可见地上堆满了骷髅。由于此处长年不见天日,导致空气中布满了毒素,一旦吸入体内,便会全身溃烂而死。幸好yifenfei早有防备,提前备好了解药材料(各种浓度的万能药水)。现在只需按照配置成不同比例的浓度。现已知yifenfei随身携带有n种浓度的万能药水,体积V都相同,浓度则分别为Pi%。并且知道,针对当时

2015-07-14 09:28:52 420

原创 HDU 1249 三角形

用N个三角形最多可以把平面分成几个区域? Input输入数据的第一行是一个正整数T(1 Output对于每组测试数据,请输出题目中要求的结果.  Sample Input212 Sample Output28每多一个三角形 其中一条边就和前 N-1个三角形的一两条边相交 所以多了3*2*(N-1)个交点

2015-07-14 09:27:46 375

原创 HDU 1004 Let the Balloon Rise

Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will cou

2015-07-14 09:24:59 288

空空如也

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

TA关注的人

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