
ACM_数据结构
文章平均质量分 78
HQD因为有趣所以做题
这个作者很懒,什么都没留下…
展开
-
石子合并
【石子合并】 在一个圆形操场的四周摆放着n 堆石子。现要将石子有次序地合并成一堆。规定每次只能选相邻的2 堆石子合并成新的一堆,并将新的一堆石子数记为该次合并的得分。 试设计一个算法,计算出将n堆石子合并成一堆的最小得分和最大得分。【输入文件】包含两行,第1 行是正整数n(1第2行有n个数,分别表示每堆石子的个数。【输出文件】输出两行转载 2010-02-19 14:07:00 · 5025 阅读 · 3 评论 -
JOJ2035: Leaf Nodes
2035: Leaf NodesStatusIn/OutTIME LimitMEMORY LimitSubmit TimesSolved UsersJUDGE TYPEstdin/stdout1s10240K224104StandardKate is learning about binar原创 2010-02-19 14:12:00 · 954 阅读 · 0 评论 -
二叉树的操作(建树,先序遍历,交换左右子树,销毁
/*建立一棵二叉树,实现先序遍历,左右子树的交换和销毁二叉树的操作。*/#include #includeusing namespace std;typedef struct BiTNode { char data; struct BiTNode *lchild , *rchild ;//}BiTNode,*BiTree;void CreateBiTree(Bi原创 2010-02-19 14:13:00 · 4741 阅读 · 1 评论 -
1716: Divisors(素数筛选)
StatusIn/OutTIME LimitMEMORY LimitSubmit TimesSolved UsersJUDGE TYPEstdin/stdout3s8192K266100StandardMathematicians love all sorts of odd properties of num原创 2010-03-03 15:52:00 · 1202 阅读 · 0 评论 -
JOJ 2442: Be efficient 线段树的做法
<br />2442: Be efficientResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE3s8192K876147Standard<br />Given a triangle and the length of its edges,we could calculate its area easily. But the task is complicated by that given lots of triangles and several in原创 2010-07-07 09:15:00 · 695 阅读 · 0 评论 -
树状数组
<br /> 树状数组 <br />关键字: 算法 树状数组<br />原文见: http://old.blog.edu.cn/user3/Newpoo/archives/2007/1712628.shtml树状数组是一种非常优雅的数据结构. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一区间元素之和的时候,可以考虑使用树状数组. 最直接的算法可以在O(1)时间内完成一次修改,但是需要O(n)时间来进行一次查询.而树状数组的修改和查询均可在O(log(n))的时间内完成. 假设a[1...N]为转载 2010-07-07 16:07:00 · 411 阅读 · 0 评论 -
JOJ 2445: Tree 线段树
<br /> 2445: TreeResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE2s16384K38440Standard<br />in this problem , i will give you a n-vertex-01-tree with the vertex numbered with 1 as root , as it states,the tree has n vertexes, each node is marked from 1 to原创 2010-07-07 23:06:00 · 500 阅读 · 0 评论 -
POJ 2481 Cows 树状数组
<br />CowsTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 4786 Accepted: 1478<br />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 f原创 2010-07-08 13:38:00 · 659 阅读 · 1 评论 -
POJ 2299 Ultra-QuickSort
<br />Ultra-QuickSortTime Limit: 7000MS Memory Limit: 65536KTotal Submissions: 15420 Accepted: 5435<br />DescriptionIn this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping t原创 2010-07-08 19:25:00 · 590 阅读 · 1 评论 -
POJ 2777 Count Color 线段树
Count ColorTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 13340 Accepted: 3790<br />DescriptionChosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems. Here, we get a new problem. <br /><b原创 2010-07-06 14:27:00 · 729 阅读 · 1 评论 -
HDU 1698 Just a Hook 线段树
Just a HookTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2589 Accepted Submission(s): 1127Problem DescriptionIn the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of原创 2010-07-07 11:48:00 · 742 阅读 · 0 评论 -
树状数组学习系列1 之 初步分析
<br />树状数组学习系列1 之 初步分析<br /> 其实学树状数组说白了就是看那张图,那张树状数组和一般数组的关系的,看懂了基本就没问题了,推荐下面这个教程:http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=binaryIndexedTrees<br /><br /> 下面对树状数组进行一些分析。<br />inline int Lowbit(int x)<br />{<br /> return x & (-转载 2010-07-07 23:09:00 · 568 阅读 · 0 评论 -
POJ 2352 Stars 树状数组
<br />StarsTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 13167 Accepted: 5654<br />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原创 2010-07-08 10:12:00 · 567 阅读 · 0 评论 -
HDU 1754 I Hate It 线段树
<br /><br />I Hate ItTime Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)<br />Total Submission(s): 4605 Accepted Submission(s): 1581<br /><br /><br />Problem Description很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。<br />这让很多学原创 2010-07-06 23:58:00 · 472 阅读 · 0 评论 -
POJ 1195 Mobile phones 二维树状数组
<br /><br />Mobile phonesTime Limit: 5000MS Memory Limit: 65536KTotal Submissions: 6658 Accepted: 2809<br />DescriptionSuppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is divided into squares. T原创 2010-07-08 20:25:00 · 480 阅读 · 1 评论 -
HDU 1166敌兵布阵 线段树
敌兵布阵Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3290 Accepted Submission(s): 1307Problem DescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的原创 2010-07-06 22:39:00 · 530 阅读 · 0 评论 -
3067 Japan 树状数组
<br /><br />JapanTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 8532 Accepted: 2290<br />DescriptionJapan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Japan is tall island with N cities on the East c原创 2010-07-08 22:32:00 · 583 阅读 · 0 评论 -
并查集学习
<br />并查集学习 转载 http://blog.youkuaiyun.com/StudyRush/archive/2010/02/01/5274729.aspx<br />如果对并查集不熟悉的话,具体的理论知识可以参考《算法导论》第21章,或者百度或者Google一下都可以,并查集有两部分很重要就是查找和合并,另外并查集一般都是用森林表示法,用链表效率低,其实用森林表示法才能够显示并查集的巨大优势。并查集的完美表现就是实现最小生成树(Kruskal+并查集),当然也不知这样一种应用,如果你熟悉并查集,那么就可以很转载 2010-07-08 23:22:00 · 474 阅读 · 0 评论 -
1611 The Suspects 并查集
<br />The SuspectsTime Limit: 1000MS Memory Limit: 20000KTotal Submissions: 7748 Accepted: 3674<br />DescriptionSevere acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To mi原创 2010-07-09 15:08:00 · 399 阅读 · 0 评论 -
2182 Lost Cows(线段树)
<br /><br /> <br />Lost CowsTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4888 Accepted: 3062<br />DescriptionN (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacular display of poor judgment, they visited the neighbo原创 2010-07-15 16:43:00 · 635 阅读 · 0 评论 -
POJ 3468 A Simple Problem with Integers 成段更新,总区间求和
<br /><br />A Simple Problem with IntegersTime Limit: 5000MS Memory Limit: 131072KTotal Submissions: 12302 Accepted: 2958Case Time Limit: 2000MS<br />Description<br />You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations.原创 2010-07-16 11:25:00 · 611 阅读 · 0 评论 -
HDU 1394 树状数组
<br />#include<stdio.h><br />#include<algorithm><br />#include<string.h><br />using namespace std;<br />struct t<br />{<br /> int id,num;<br />}s[5001];<br />int b[5001];<br />int tree[5001],n;<br />bool cmp(t a,t b)<br />{<br /> return a.num<b.num;<原创 2010-07-14 23:19:00 · 585 阅读 · 0 评论 -
POJ 2528 Mayor's posters 线段树的水过
<br />离散化很讲究,相邻差1,不相邻差2 <br />例如这组数据31 101 36 10显然有三个poster可见,1-3,4-5,6-10但排序离散化之后:排序后:1 1 3 6 10离散化后:1对应1,3对应2,6对应3,10对应4原始数据的三个区间就变为:1 41 23 4结果可见的poster就只有两个,1-2,3-4。。。。。#include<stdio.h>#include<algorithm>#include<string.h原创 2010-07-18 15:02:00 · 572 阅读 · 0 评论 -
POJ 2528 Mayor's posters
<br />线段树NB!63MS...Mayor's postersTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 13408 Accepted: 3722<br />DescriptionThe citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their el原创 2010-07-18 16:07:00 · 1439 阅读 · 0 评论 -
二维线段树
<br /><br />#include<stdio.h><br />#include<algorithm><br />using namespace std;<br />#define LL(x) (x<<1)<br />#define RR(x) (x<<1|1)<br /> <br />struct Sub_Seg_Tree<br />{<br /> int left,right,val;<br /> int mid() {return (left+right)/2;}<br />原创 2010-07-18 11:54:00 · 525 阅读 · 0 评论 -
hdu 2871 Memory Control 线段树
<br /><br />Memory ControlTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)<br />Total Submission(s): 360 Accepted Submission(s): 82<br /><br /><br />Problem DescriptionMemory units are numbered from 1 up to N.<br />A s原创 2010-07-23 10:17:00 · 2048 阅读 · 0 评论 -
3667 Hotel
HotelTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 2523 Accepted: 957<br />Description<br />The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ev原创 2010-07-22 11:37:00 · 974 阅读 · 2 评论 -
poj hdu Tunnel Warfare
<br /><br />Tunnel WarfareTime Limit: 1000MS Memory Limit: 131072KTotal Submissions: 2814 Accepted: 1044<br />Description<br />During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain.原创 2010-07-22 16:57:00 · 1052 阅读 · 0 评论 -
3321
<br />Apple TreeTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 8522 Accepted: 2341<br />Description<br />There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has原创 2010-07-27 09:39:00 · 624 阅读 · 0 评论 -
POJ 3264 Balanced Lineup
Balanced LineupTime Limit: 5000MS Memory Limit: 65536KTotal Submissions: 12699 Accepted: 5868Case Time Limit: 2000MS<br />Description<br />For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John de原创 2010-07-28 08:31:00 · 623 阅读 · 0 评论 -
hdu 3410 省赛
Passing the MessageTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 116 Accepted Submission(s): 74Problem DescriptionWhat a sunny day! Let’s go picnic and have barbecue! Today, all kids in “Sun Flow原创 2010-07-31 12:25:00 · 1895 阅读 · 0 评论 -
2155 Matrix 二维线段树
MatrixTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 7121 Accepted: 2657DescriptionGiven 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 We can change原创 2010-08-03 23:12:00 · 511 阅读 · 0 评论 -
浙大月赛 Osaisen Choudai! //线段树+DP
<br /> <br />Osaisen Choudai!Time Limit: 3 Seconds Memory Limit: 65536 KB <br />A saisenbako (賽銭箱, offertory, or religious collection box) is situated in front of the hall of Hakurei Shrine. Hakurei Reimu (博麗霊夢), the miko of Hakurei Shrine, may原创 2010-08-22 17:36:00 · 788 阅读 · 0 评论 -
3461 Oulipo //KMP
<br /><br />OulipoTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 5864 Accepted: 2222<br />Description<br />The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo g原创 2010-08-24 20:59:00 · 916 阅读 · 0 评论 -
2752 Seek the Name, Seek the Fame //KMP
Seek the Name, Seek the FameTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 5243 Accepted: 2308<br />DescriptionThe little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their n原创 2010-08-25 09:10:00 · 529 阅读 · 0 评论 -
POJ 1330 Nearest Common Ancestors(tarjan LCA 算法)
POJ 1330 Nearest Common Ancestors(tarjan LCA 算法)<br /> 关于LCA和RMQ问题<br /><br />一、最近公共祖先(Least Common Ancestors)<br />对于有根树T的两个结点u、v,最近公共祖先LCA(T,u,v)表示一个结点x,满足x是u、v的祖先且x的深度尽可能大。另一种理解方式是把T理解为一个无向无环图,而LCA(T,u,v)即u到v的最短路上深度最小的点。<br />这里给出一个LCA的例子:<br />例一<br />转载 2010-08-25 20:38:00 · 964 阅读 · 1 评论 -
3080 Blue Jeans//KMP
<br />Blue JeansTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4785 Accepted: 1962<br />DescriptionThe Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thous原创 2010-08-25 11:43:00 · 662 阅读 · 0 评论 -
1330 Nearest Common Ancestors //LCA
<br /><br />Nearest Common AncestorsTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 7458 Accepted: 3889<br />DescriptionA rooted tree is a well-known data structure in computer science and engineering. An example is shown below: <br /><br /><br原创 2010-08-25 21:21:00 · 640 阅读 · 0 评论 -
1986 Distance Queries //LCA
Distance QueriesTime Limit: 2000MS Memory Limit: 30000KTotal Submissions: 3708 Accepted: 1315Case Time Limit: 1000MS<br />DescriptionFarmer John's cows refused to run in his marathon since he chose a path much too long for their leisurely lifestyle. He the原创 2010-08-26 19:57:00 · 671 阅读 · 1 评论 -
1986 Distance Queries //LCA+VECTOR 贼慢
<br /><br />Distance QueriesTime Limit: 2000MS Memory Limit: 30000KTotal Submissions: 3709 Accepted: 1316Case Time Limit: 1000MS<br />DescriptionFarmer John's cows refused to run in his marathon since he chose a path much too long for their leisurely l原创 2010-08-26 20:42:00 · 619 阅读 · 0 评论