数据结构/算法
linjiaqingggg
这个作者很懒,什么都没留下…
展开
-
先根递归建立二叉树(顺序表示法)
#include #include #include #define maxn 1005#include #include using namespace std;class node{public: node(char c,node*l=NULL,node*r=NULL):c(c),l(l),r(r){}; node *l,*r; char c;};原创 2016-03-29 21:17:10 · 1295 阅读 · 0 评论 -
c++模板---堆
#include #include #include using namespace std;templateclass priority{ T * e; int sz;public: priority(int n=1005); priority(T * a,int n); T top(); void pop(); void p原创 2016-03-12 22:40:52 · 274 阅读 · 0 评论 -
反转链表
#include #include using namespace std;class node{public: int data; node * next; node(int d):data(d),next(NULL) { } node(){}};void add(node * &head,node * &tail,int data原创 2016-02-27 21:32:22 · 266 阅读 · 0 评论 -
倒序输出链表
//递归实现#include #include using namespace std;class node{public: int data; node * next; node(int d):data(d),next(NULL) { }};class lists{ node * head; node * tail原创 2016-02-27 19:29:57 · 395 阅读 · 0 评论 -
计算两个日期之间的天数
机智题,分别算两个现在到公元的天数,相减#include int sum(int y,int m,int d){int x[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};int i,s=0;for(i=1;i<y;i++)if((i%4==0 && i%100!=0 )|| i%400==0)s+=366;//闰年elses+=365原创 2015-12-12 12:47:01 · 438 阅读 · 0 评论 -
迷宫问题之最短路径bfs
#include #include #include #include #include #include #include #include using namespace std;#define maxn 105#define inf 0x3f3f3f3ftypedef long long LL;int n,m;char mp[maxn][maxn];bool vi原创 2015-12-11 18:48:25 · 524 阅读 · 0 评论 -
hihocoder算法复习之 线段树单点更新
hihocoder#1077 : RMQ问题再临-线段树时间限制:10000ms单点时限:1000ms内存限制:256MB描述上回说到:小Hi给小Ho出了这样一道问题:假设整个货架上从左到右摆放了N种商品,并且依次标号为1到N,每次小Hi都给出一段区间[L, R],小Ho要做的是选出标号在这个区间内的所有商品重量最原创 2015-11-16 18:45:58 · 453 阅读 · 0 评论 -
HDU 2255 奔小康赚大钱 (KM算法 模板)
A - 奔小康赚大钱Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uSubmit StatusDescription传说在遥远的地方有一个非常富裕的村落,有一天,村长决定进行制度改革:重新分配房子。 这可是一件大事,关系到人民的住房问题啊。村里共有n间房间原创 2015-08-17 11:44:44 · 713 阅读 · 0 评论 -
UVA 348 Optimal Array Multiplication Sequence(最优矩阵链乘)
L - Optimal Array Multiplication SequenceTime Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %lluSubmit Status Practice UVA 348Appoint description: acmparand (2013-08-02原创 2015-08-09 20:25:21 · 651 阅读 · 0 评论 -
POJ 3368 Frequent values
B - Frequent valuesTime Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uSubmit Status Practice POJ 3368Appoint description: bjtu_lyc (2011-08-08)System Crawler (原创 2015-08-09 11:48:13 · 539 阅读 · 0 评论 -
POJ 3264 Balanced Lineup(st或者线段树)
A - Balanced LineupTime Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uSubmit Status Practice POJ 3264Appoint description: System Crawler (2015-08-03)Des原创 2015-08-09 00:29:03 · 1120 阅读 · 0 评论 -
Codeforces Round #312 (Div. 2) B. Amr and The Large Array
这道题对技巧和思维都是不错的锻炼。求出现最多次数的那个数在保持出现次数不变的情况下数组的最短长度。思路:1用一个vis数组来标记数组中每个数字出现的次数,可以边输入边判断,在线性时间内处理处出现次数最多的次数。注意不是那个数,因为出现的最大次数相同的数可能有多个。2线性时间扫一遍,处理处每个数的最左和最右端点的编号和区间的长度。3线性时间再扫一遍,这次只要在出现最大次数相同的数之间比较区间,即可找出出现次数最大且长度最短的子数组。原创 2015-08-07 23:55:11 · 453 阅读 · 0 评论 -
HDU 3549 Flow Problem
最大流的一些基本概念:1 流量flow: u->v 的流量为f,则相反方向的v->u的流量为-f2 容量cap:u->v的容量为c,但v->u的容量为0.(本来图中不存在的边容量都为0)3 残量cp=容量-流量。cp(u->v)=cap(u->v)-flow(u->v);4 增广路:在残量图中,一条从起点s到终点t的路径,且该路径上的所以残量的最小值要大于0.最大流ekrap算法的思想:(其实就是找增广路一步步逼近最大流)1不停的找增广原创 2015-08-06 22:47:02 · 473 阅读 · 0 评论 -
POJ 1330 Nearest Common Ancestors
lca的tarjan离线算法#include#include#include#include#includeusing namespace std;#define maxn 10505int fa[maxn],ance[maxn];vectorg[maxn],query[maxn];bool vis[maxn];int in[maxn];int n,m;原创 2015-08-05 14:48:54 · 423 阅读 · 0 评论 -
无向图的点双连通分量(tarjan模板)
#include#include#include#include#include#includeusing namespace std;#define maxn 7500#define inf 0x3f3f3f3fint n,m;int g[maxn][maxn];int clock;int low[maxn],pre[maxn];stacks;int bc;vect原创 2015-08-01 17:38:36 · 2017 阅读 · 1 评论 -
POJ 3273 Monthly Expense
B - Monthly ExpenseTime Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uSubmit Status Practice POJ 3273Appoint description: System Crawler (2015-07-20)Descr原创 2015-07-20 22:32:54 · 483 阅读 · 0 评论 -
POJ 3104 Drying
C - DryingTime Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uSubmit Status Practice POJ 3104Appoint description: System Crawler (2015-07-17)Description原创 2015-07-20 23:50:42 · 732 阅读 · 0 评论 -
I hate it (线段树)
B - I Hate ItTime Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uSubmit StatusDescription很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。 这让很多学生很反感。 不管你喜不喜欢,原创 2015-07-22 23:54:53 · 2149 阅读 · 0 评论 -
poj 3468 A Simple Problem with Integers
A Simple Problem with IntegersTime Limit:5000MS Memory Limit:131072KB 64bit IO Format:%I64d & %I64uSubmit StatusDescriptionYou have N integers, A1, A2, ... , AN. You need t原创 2015-07-23 01:31:29 · 728 阅读 · 0 评论 -
POJ 2777 Count Color
C - Count ColorTime Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uSubmit Status Practice POJ 2777Appoint description: System Crawler (2015-07-22)Descrip原创 2015-07-25 20:48:55 · 645 阅读 · 0 评论 -
无向图的割顶和桥(tarjan模板)
#include#include#include#includeusing namespace std;#define maxn 7500#define inf 0x3f3f3f3fint first[maxn],to[maxn],nxt[maxn],e;int pre[maxn],low[maxn];int clock;int iscut[maxn];void add(in原创 2015-08-01 15:32:23 · 729 阅读 · 0 评论 -
POJ 3258 River Hopscotch
思路: n高达50000, 肯定不可能是暴力枚举。我们用一个“猜”的思想,先猜这个值可以是多少,再用一个函数验证。 然后利用单调性,注意单调性是必须,不然无法进行二分搜索,猜的值满足条件,说明还可以再变小,继续二分下去。 其实这和牛顿的二分求方程的跟的思路是一样的。原创 2015-07-20 21:34:37 · 418 阅读 · 0 评论 -
hdu 2063 过山车
过山车Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uSubmit StatusDescriptionRPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了。可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个原创 2015-07-20 12:55:31 · 1039 阅读 · 0 评论 -
n皇后问题(回溯法)
#include#include#includeusing namespace std;#define maxn 10int n;bool vis[maxn];int sum;int c[maxn];bool check(int cur,int j){ if(vis[j])return false; for(int i=0;i<cur;i++){ if(j-c原创 2015-05-24 20:55:23 · 584 阅读 · 0 评论 -
UVA 111 History Grading(最长公共子序列dp)
A - History GradingTime Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %lluSubmit Status Practice UVA 111DescriptionBackgroundMany problems in Computer Scie原创 2015-07-11 01:09:37 · 633 阅读 · 0 评论 -
POJ 3461 Oulipo
D - OulipoTime Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uSubmit Status Practice POJ 3461DescriptionThe French author Georges Perec (1936–1982) once原创 2015-04-11 19:36:31 · 477 阅读 · 0 评论 -
POJ 2406 Power Strings
B - Power StringsTime Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uSubmit Status Practice POJ 2406DescriptionGiven two strings a and b we define a*b t原创 2015-04-11 19:34:59 · 526 阅读 · 0 评论 -
poj 3122 Pie 二分(最大化平均值)
PieTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 11776 Accepted: 4076 Special JudgeDescriptionMy birthday is coming up and traditionally I'm ser原创 2015-04-06 19:00:33 · 474 阅读 · 0 评论 -
POJ 1905 Expanding Rods
Expanding RodsTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 12796 Accepted: 3299DescriptionWhen a thin rod of length L is heated n degrees, it expan原创 2015-04-06 12:22:20 · 557 阅读 · 0 评论 -
POJ 1458 Common Subsequence(lcs)
Common SubsequenceTime Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64uSubmit Status Practice POJ 1458DescriptionA subsequence of a given sequence is the原创 2015-04-05 11:09:20 · 402 阅读 · 0 评论 -
(POJ1953)World Cup Noise(dp)
World Cup NoiseTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 16006 Accepted: 7904DescriptionBackground "KO-RE-A, KO-RE-A" shout 54.000 happy footb原创 2015-04-04 19:57:24 · 566 阅读 · 0 评论 -
poj 1273 Drainage Ditches(模板题)
网络流模板原创 2015-04-02 23:47:30 · 448 阅读 · 0 评论 -
POJ 2551 Ones(取模)
111111%n=(1%n+10%n+100%n+1000%n+10000%n)%n11%n=(10%n+1%n)%n;111%n=(110%n+1%n)=(10*11%n+1)%n由此推出公式int temp=1;int cnt=1;while(temp!=0){ temp=(temp*10+1)%n; cnt++;}cout<<cnt<<endl;原创 2015-03-30 00:17:59 · 396 阅读 · 0 评论 -
hdu 1561 The more, The Better(树形dp+01背包)
The more, The BetterTime Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uSubmit StatusDescriptionACboy很喜欢玩一种战略游戏,在一个地图上,有N座城堡,每座城堡都有一定的宝物,在每次游戏中ACboy允许攻克M个城堡并获原创 2015-03-28 11:41:16 · 603 阅读 · 0 评论 -
HDU 1557 权利指数
权利指数Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 898 Accepted Submission(s): 609Problem Description在选举问题中,总共有n个小团体,每个小团体拥有一定数量原创 2015-03-26 20:23:11 · 750 阅读 · 0 评论 -
HDU 1285 确定比赛名次(拓扑排序)
拓扑排序的思想:找到入度为0的点,此点指向的所有点入度减一,删去此点。重复此操作。队列实现:(1)找到入度为0的点,入队。 (2)出队时,此点指向的所有点入度减一 (3)此时,若有入度为0的,入队 (4)重复以上操作。题目要求同个等级时编号小的先出,所以用优先队列。原创 2015-03-25 22:56:22 · 595 阅读 · 0 评论 -
HDU 1358 KMP
A - KMPTime Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uSubmit Status Practice HDU 1358DescriptionFor each prefix of a given string S with N characters原创 2015-03-24 00:06:34 · 553 阅读 · 0 评论 -
hdu1569find the safest road(floyd变形求最大安全值)
find the safest roadTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7845 Accepted Submission(s): 2786Problem DescriptionXX星球有很多城原创 2015-03-21 00:09:06 · 912 阅读 · 0 评论 -
命运(dp)
命运Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11066 Accepted Submission(s): 3898Problem Description穿过幽谷意味着离大魔王lemon已经无限接近了!原创 2015-03-20 21:16:32 · 543 阅读 · 0 评论 -
免费馅饼(dp)
免费馅饼Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 28610 Accepted Submission(s): 9765Problem Description都说天上不会掉馅饼,但有一天gameboy正走在原创 2015-03-20 19:37:52 · 539 阅读 · 0 评论