POJ 2914 Minimum Cut【最小割】
摘要:DescriptionGiven an undirected graph, in which two vertices can be connected by multiple edges, what is the size of the minimum cut of the graph? i.e. how many edges must be removed at least to disconnect the graph into two subgraphs?InputInput contains multiple test cases. Each test case starts wit
阅读全文
posted @
2012-08-30 00:10
crying_Dream
阅读(185)
推荐(0)
ZOJ 3633 Alice's present【线段树】
摘要:As a doll master, Alice owns a wide range of dolls, and each of them has a number tip on it's back, the tip can be treated as a positive integer. (the number can be repeated). One day, Alice hears that her best friend Marisa's birthday is coming , so she decides to sent Marisa some dolls for
阅读全文
posted @
2012-08-29 19:20
crying_Dream
阅读(206)
推荐(0)
ZOJ 3643 Keep Deleting【KMP+栈模拟】
摘要:Assume that string A is the substring of string B if and only if we can find A in B, now we have a string A and another string B, your task is to find a A in B from B's left side to B's right side, and delete it from B till A is not a substring of B, then output the number of times you do th
阅读全文
posted @
2012-08-27 20:32
crying_Dream
阅读(430)
推荐(0)
关于 KMP
摘要:发现KMP, 我都已经忘了,找到我之前写的总结,粘贴一下,保存留念吧; 发现之前我写的总结和你好玩的样子,自己都看笑了...hia hia hia hia...KMP我只了解你一点点KMP:即串模式匹配,(KMP分别是三个人名字的简称)。学习KMP推荐:严蔚敏数据结构课件。真心说她讲的很到位。能让你明白next[],的求法。简单算法基本思想(当字符串长度不大时):用i, j指主串和模式串。通过一个个比较,直至模式串与主串一一匹配则称匹配成功,否则失败。改进办法:不用将i指针一次次回朔,而是利用以匹配的结果是是模式串尽可能的向前滑动。 这里需要一个next[100], 的函数。函数模板:K...
阅读全文
posted @
2012-08-27 20:20
crying_Dream
阅读(193)
推荐(0)
ZOJ 3635 Cinema in Akiba【树状数组+二分查找】
摘要:Cinema in Akiba (CIA) is a small but very popular cinema in Akihabara. Every night the cinema is full of people. The layout of CIA is very interesting, as there is only one row so that every audience can enjoy the wonderful movies without any annoyance by other audiences sitting in front of him/her.
阅读全文
posted @
2012-08-26 21:38
crying_Dream
阅读(447)
推荐(0)
ZOJ Information Sharing 【并查集+set】
摘要:There is going to be a test in the kindergarten. Since the kids would cry if they get a low score in the test, the teacher has already told every kid some information about the test in advance.But the kids are not satisfied with the information teacher gave. They want to get more. On the testing d..
阅读全文
posted @
2012-08-26 20:31
crying_Dream
阅读(282)
推荐(0)
HDU 4263 Red/Blue Spanning Tree【最小生成树原理】
摘要:Problem DescriptionGiven an undirected, unweighted, connected graph, where each edge is colored either blue or red, determine whether a spanning tree with exactly k blue edges exists.InputThere will be several test cases in the input. Each test case will begin with a line with three integers:n m kWh
阅读全文
posted @
2012-08-25 23:19
crying_Dream
阅读(535)
推荐(0)
HDU 4259 Double Dealing 【离散数学】
摘要:Problem DescriptionTake a deck of n unique cards. Deal the entire deck out to k players in the usual way: the top card to player 1, the next to player 2, the kth to player k, the k+1st to player 1, and so on. Then pick up the cards – place player 1′s cards on top, then player 2, and so on, so that p
阅读全文
posted @
2012-08-25 19:53
crying_Dream
阅读(448)
推荐(0)
POJ 1273 Drainage Ditches【最大流EK算法模板题】
摘要:DescriptionEvery time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage ditches so that Bessie's clover patch i
阅读全文
posted @
2012-08-23 21:08
crying_Dream
阅读(241)
推荐(0)
POJ 1019 Number Sequence【数论】
摘要:DescriptionA 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 integer numbers ranging from 1 to k, written one after another.For example, the first 80 digits of
阅读全文
posted @
2012-08-17 22:12
crying_Dream
阅读(414)
推荐(0)
HDU 4091 Zombie’s Treasure Chest 【杂题】%
摘要:Problem Description Some brave warriors come to a lost village. They are very lucky and find a lot of treasures and a big treasure chest, but with angry zombies. The warriors are so brave that they decide to defeat the zombies and then bring all the treasures back. A brutal long-drawn-out battle la.
阅读全文
posted @
2012-08-17 16:38
crying_Dream
阅读(480)
推荐(0)
POJ 3125 Printer Queue【暴力模拟】
摘要:DescriptionThe only printer in the computer science students' union is experiencing an extremely heavy workload. Sometimes there are a hundred jobs in the printer queue and you may have to wait for hours to get a single page of output.Because some jobs are more important than others, the Hacker
阅读全文
posted @
2012-08-13 19:00
crying_Dream
阅读(940)
推荐(0)
HDU 1969 Pie 【二分】
摘要:Problem DescriptionMy birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of them gets a piece of pie. This should be one piece of one pie, not several sm
阅读全文
posted @
2012-08-13 10:39
crying_Dream
阅读(179)
推荐(0)
HDU 4004 The Frog's Games 【二分】
摘要:Problem DescriptionThe annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes to jump over the river. The width of the river is L (1<= L <= 1000000000). There are n
阅读全文
posted @
2012-08-13 10:33
crying_Dream
阅读(342)
推荐(0)
POJ 3273 Monthly Expense【二分】
摘要:DescriptionFarmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has already calculated and recorded the exact amount of money (1 ≤ moneyi ≤ 10,000) that he will need to spend each day over the next N (1 ≤ N ≤ 100,000) days.FJ wants to create a
阅读全文
posted @
2012-08-13 10:24
crying_Dream
阅读(934)
推荐(0)
POJ 2001 Shortest Prefixes【第一棵字典树】
摘要:DescriptionA prefix of a string is a substring starting at the beginning of the given string. The prefixes of "carbon" are: "c", "ca", "car", "carb", "carbo", and "carbon". Note that the empty string is not considered a prefix in
阅读全文
posted @
2012-08-13 10:11
crying_Dream
阅读(383)
推荐(0)
字典树【模板】
摘要:字典树:也是trie树,根节点不包含字符,除了根节点外每个节点包含一个字符,而且都不一样。从根结点单到某结点的连线就是所对应的字符串。可以查找,插入和删除。实现过程:从根节点开始,查找第一个单词,找到后再找相应的子树进行循环这个过程...模板如下:struct node{ int cnt; //记录该字符出现次数 node *next[27];}*root; //root根节点 void Maketree(char *str) /*插入*/{ int ans, i, len; node *p, *q; p=root; len=strl...
阅读全文
posted @
2012-08-13 10:08
crying_Dream
阅读(193)
推荐(0)
POJ 3264 Balanced Lineup【RMQ-ST算法-区间最值】
摘要:DescriptionFor the daily milking, Farmer John'sNcows (1 ≤N≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate Frisbee with some of the cows. To keep things simple, he will take a contiguous range of cows from the milking lineup to play the game.
阅读全文
posted @
2012-08-11 17:58
crying_Dream
阅读(169)
推荐(0)
POJ 3250 Bad Hair Day【单调栈】
摘要:DescriptionSome of Farmer John'sNcows (1 ≤N≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cows' heads.Each cowihas a specified heighthi(1 ≤hi≤ 1,000,000,000) and is stan
阅读全文
posted @
2012-08-11 15:21
crying_Dream
阅读(495)
推荐(0)
POJ 2823 Sliding Window【单调对列经典题目】
摘要:DescriptionAn array of sizen≤ 106is given to you. There is a sliding window of sizekwhich is moving from the very left of the array to the very right. You can only see theknumbers in the window. Each time the sliding window moves rightwards by one position. Following is an example:The array is[13-1-
阅读全文
posted @
2012-08-11 11:02
crying_Dream
阅读(161)
推荐(0)
HLG 1522 子序列的和【队列的应用】
摘要:Description输入一个长度为n的整数序列(A1,A2,……,An),从中找出一段连续的长度不超过m的子序列,使得这个子序列的和最大。Input有多组测试数据,不超过20组测试数据。对于每组测试的第一行,包含两个整数n和m(n,m<=10^5),表示有n个数,子序列长度限制为m,表示这个序列的长度,第二行为n个数,每个数的范围为[-1000, 1000]。Output对于每组测试数据,输出最大的子序列和,并换行。Sample Input3 11 2 33 2-1000 1000 1Sample Output31001思路:看的比较懂得参考资料:http://blog.csdn.ne
阅读全文
posted @
2012-08-11 10:58
crying_Dream
阅读(344)
推荐(0)
HDU 1754 I hate it【线段树之单点替换区间最值】
摘要:Problem Description很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。这让很多学生很反感。不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。Input本题目包含多组测试,请处理到文件结束。在每个测试的第一行,有两个正整数 N 和 M ( 0<N<=200000,0<M<5000 ),分别代表学生的数目和操作的数目。学生ID编号分别从1编到N。第二行包含N个整数,代表这N个学生的初始成绩,其中第i个数代表ID为i的学生的成绩。接下来有M行。每一行有一个
阅读全文
posted @
2012-08-09 11:43
crying_Dream
阅读(205)
推荐(0)
线段树模板【1】
摘要:单点增减,区间求和View Code struct Node { int l, r, mid, sum;}node[MAX]; void init(int a, int b, int n)//init(1,n+1,1); { node[n].l=a; node[n].r=b; node[n].mid=(a+b)/2; node[n].sum=0; if(a+1==b) return ; init(a, (a+b)/2; 2*n); init((a+b)/2, b, 2*n+1);}void add(int pos, int v...
阅读全文
posted @
2012-08-09 11:38
crying_Dream
阅读(120)
推荐(0)
推荐线段树资料
摘要:http://www.notonlysuccess.com/index.php/segment-tree-complete/
阅读全文
posted @
2012-08-09 11:09
crying_Dream
阅读(115)
推荐(0)
HDU 1166 临兵布敌【树状数组】
摘要:Problem DescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算
阅读全文
posted @
2012-08-09 08:14
crying_Dream
阅读(233)
推荐(0)
POJ 2155 Matrix【二维树状数组】POJ 2155【
摘要:DescriptionGiven an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row and j-th column. Initially we have A[i, j] = 0 (1 <= i, j <= N). We can change the matrix in the following way. Given a rectangle whose upper-left corner is (x1, y1) and lower-right cor
阅读全文
posted @
2012-08-09 08:02
crying_Dream
阅读(213)
推荐(0)
二维树状数组模板
摘要:int Lowbit(int t){ return t&(-t);}void add(int x, int y){ int i=y; while(x<=n) { y=i; while(y<=n) { c[x][y]++; y+=Lowbit(y); } x+=Lowbit(x); }}int Sum(int x, int y){ int i=y, sum=0; while(x>0) { y=i; while...
阅读全文
posted @
2012-08-09 07:50
crying_Dream
阅读(621)
推荐(0)
POJ 2481 Cows【树状数组】
摘要:DescriptionFarmer John's cows have discovered that the clover growing along the ridge of the hill (which we can think of as a one-dimensional number line) in his field is particularly good.Farmer John has N cows (we number the cows from 1 to N). Each of Farmer John's N cows has a range of cl
阅读全文
posted @
2012-08-08 21:14
crying_Dream
阅读(421)
推荐(0)
POJ 2352 Stars【树状数组】
摘要:DescriptionAstronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. Astronomers want to know the distribution of the leve
阅读全文
posted @
2012-08-08 15:47
crying_Dream
阅读(1437)
推荐(0)
树状数组模板
摘要:int c[N], n; int Lowbit(int t) //求某一点的管辖范围{ return t&(t^(t-1)); //也可以写成 return t&(-t);}int Sum(int end) //求区间和{ int sum = 0; while(end > 0) { sum += c[end]; end -= Lowbit(end); } return sum;}void add(int li, int val) //开始构建一个树状数组, 也可以修改数组{ while(li<=n) { ...
阅读全文
posted @
2012-08-08 15:36
crying_Dream
阅读(313)
推荐(0)
POJ 2236 Wireless Network【裸并查集+计算几何】
摘要:DescriptionAn earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the network were all broken. The computers are repaired one by one, and the network gradually
阅读全文
posted @
2012-08-07 13:46
crying_Dream
阅读(224)
推荐(0)
POJ 1308 Is It A Tree?【裸的并查集】
摘要:Language:DescriptionA tree is a well-known data structure that is either empty (null, void, nothing) or is a set of one or more nodes connected by directed edges between nodes satisfying the following properties.There is exactly one node, called the root, to which no directed edges point.Every node
阅读全文
posted @
2012-08-07 13:42
crying_Dream
阅读(189)
推荐(0)
HLG 1519 Tower Parking【模拟】
摘要:Description There is a new revolution in the parking lot business: the parking tower. The concept is simple: you drive your car into the elevator at the entrance of the tower, and the elevator and conveyor belts drag the car to an empty parking spot, where the car remains until you pick it up. When
阅读全文
posted @
2012-08-06 00:24
crying_Dream
阅读(249)
推荐(0)
HLG 1513 Containers【暴力枚举】
摘要:Description At a container terminal, containers arrive from the hinterland, one by one, by rail, by road,or by small ships. The containers are piled up as they arrive. Then the huge cargo ships arrive, each one capable of carrying thousands of containers. The containers are loaded into the ships tha
阅读全文
posted @
2012-08-06 00:16
crying_Dream
阅读(255)
推荐(0)
POJ 1182 食物链【带种类并查集】
摘要:Description动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。 现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。 有人用两种说法对这N个动物所构成的食物链关系进行描述: 第一种说法是"1 X Y",表示X和Y是同类。 第二种说法是"2 X Y",表示X吃Y。 此人对N个动物,用上述两种说法,一句接一句地说出K句话,这K句话有的是真的,有的是假的。当一句话满足下列三条之一时,这句话就是假话,否则就是真话。 1) 当前的话与前面的某些真的话冲突,就是假话; 2)
阅读全文
posted @
2012-08-05 11:23
crying_Dream
阅读(234)
推荐(0)
POJ 1703 Find them, Catch them【带种类的并查集】
摘要:DescriptionThe police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to identify which gang a criminal belongs to. The present question is, given two criminals; do they belong t
阅读全文
posted @
2012-08-04 21:51
crying_Dream
阅读(421)
推荐(0)
POJ 1035 Spell checker【字符串处理】
摘要:DescriptionYou, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given words using a known dictionary of all correct words in all their forms.If the word is absent in the dictionary then it can be replaced by correct words (
阅读全文
posted @
2012-08-03 23:44
crying_Dream
阅读(297)
推荐(0)
HLG 1507 水神的栅栏【判断线段相交+并查集】
摘要:Description 水神在赚了一笔钱之后,购买了一座庄园,做起了农场主,水神的农场都是靠栅栏围墙来分成很多部分并且围成外面的围墙的,但是最近一段时间,水神的庄园遭到了神兽的袭击,神兽撞破了很多处栅栏,这让水神非常苦恼,为了弄清楚自己的栅栏还有哪些地方时连着的,水神画了一张平面图,每一段栅栏在图上表示成一个线段,这些线段有的会相交,有的不会。 水神需要知道两段栅栏是否可以连起来。Input有多组输入数据,每组数据:第一行一个整数n表示水神农场的栅栏的个数(n<13)接下来n行,每行四个整数x1,y1,x2,y2分别表示栅栏的两个端点坐标然后下面若干行是对栅栏连接情况的询问,每行两个整数
阅读全文
posted @
2012-08-03 00:22
crying_Dream
阅读(226)
推荐(0)
HLG 1506 屠夫和狙击手【判断点在线段上+线段与圆相交】
摘要:DescriptionDOTA是一个大学生中非常受欢迎的一款游戏,游戏中天灾军团和近卫军团一直处于对抗状态,如果近卫军团的世界之树或者天灾军团的冰封王座被摧毁,那么游戏会立即结束。游戏中最有意思的是就两个军团的基地内都有一个可以补充各自英雄能量的泉水。当然泉水不仅仅是一个能量补给站,而且还会很快杀死想靠近的敌方英雄。但是无论如何泉水奈何不了近卫军团的矮人狙击手,因为矮人狙击手的攻击范围要比泉水远很多。因此矮人狙击手甚至有能力拆掉一个泉水。有一个生命值不多的矮人狙击手要攻击天灾军团的泉水,这个猥琐的行为是天灾军团不能容忍的,天灾军团的英雄屠夫是在看不下去了,屠夫准备出马收拾这个狙击手。屠夫有一把
阅读全文
posted @
2012-08-03 00:12
crying_Dream
阅读(372)
推荐(0)