- 博客(261)
- 收藏
- 关注
原创 字符串编辑距离及另类
设A和B是2个字符串。要用最少的字符操作将字符串A转换为字符串B。这里所说的字符操作包括:(1)删除一个字符;(2)插入一个字符;(3)将一个字符改为另一个字符。将字符串A变换为字符串B所用的最少字符操作数称为字符串A到B的编辑距离dp[i][j]表示源串S[0...i]到目标串T[0...j]的最短编辑距离,则dp[i][0]=i;dp[0][j]=j;dp[
2016-07-13 21:55:37
1127
原创 根据二叉树先序中序序列输出后序
#include #include #include #include #include using namespace std;#define inf 0x3f3f3f3ftypedef struct node{ char x; struct node *lc,*rc;}node,*tree;char pre[100],in[100],post[100];v
2016-03-13 19:49:41
1268
原创 合唱队形
题目描述:N位同学站成一排,音乐老师要请其中的(N-K)位同学出列,使得剩下的K位同学不交换位置就能排成合唱队形。合唱队形是指这样的一种队形:设K位同学从左到右依次编号为1, 2, …, K,他们的身高分别为T1, T2, …, TK,则他们的身高满足T1 Ti+1 > … > TK (1 你的任务是,已知所有N位同学的身高,计算最少需要几位同学出列,可以使得剩下的同学排成合
2016-03-13 14:26:24
506
原创 拦截导弹
题目描述:某国为了防御敌国的导弹袭击,开发出一种导弹拦截系统。但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度。某天,雷达捕捉到敌国的导弹来袭,并观测到导弹依次飞来的高度,请计算这套系统最多能拦截多少导弹。拦截来袭导弹时,必须按来袭导弹袭击的时间顺序,不允许先拦截后面的导弹,再拦截前面的导弹。 输入:每组
2016-03-06 17:37:02
369
原创 先序建二叉树,中序遍历
#include#include#includeusing namespace std;typedef struct node{ char x; struct node* lc,* rc;}node,*tree;char s[1000];int m;void build(tree &t){ int l=strlen(s); if(m>=l) re
2016-02-29 20:30:23
441
原创 大数阶乘&&大数乘法
#include#include#include#include#includeusing namespace std;#define inf 0x3f3f3f3fint a[10005];int main(){ int i,j,n,c,s; while(~scanf("%d",&n)) { memset(a,0,sizeof a);
2016-02-28 20:38:47
582
原创 大数加法
#include#include#include#include#includeusing namespace std;#define inf 0x3f3f3f3fchar a[100],b[100];int c[100],d[100];void get(char x[],int y[]){ int i,l; l=strlen(x); for(i=0;i
2016-02-28 20:28:22
248
原创 Dijkstra算法
#include#include#include#include#includeusing namespace std;#define inf 0x3f3f3f3fint map[205][205],d[205],v[205],n,m;int Dijkstra(int s,int t){ int i,j,min,k; memset(d,inf,sizeof d);
2016-02-28 19:56:02
305
原创 prim最小生成树
#include#include#include#include#includeusing namespace std;#define inf 0x3f3f3f3fint m,n,g[200][200],d[200];bool v[200];int prim(){ int i,j,k,min,s=0; for(i=1;i<=m;i++) {
2016-02-26 14:56:00
268
原创 快速排序
#include#include#includeusing namespace std;int a[100];void quicksort(int l,int r){ int i,j,t,x; if(l>r) return ; i=l,j=r; t=a[l];//t中存基准数 while(i!=j) { while(a[j
2016-02-26 12:28:18
291
原创 kmp算法
#include#include#include#include#include#includeusing namespace std;char s[1000],c[100];int next[1000];void getn(){ int i=0,j=-1; next[0]=-1; while(c[i]) { if(j==-1||
2016-02-25 20:27:02
284
原创 HDU - 5187 - zhx's contest
Problem DescriptionAs one of the most powerful brushes, zhx is required to give his juniors n problems.zhx thinks the ith problem's difficulty is i. He wants to arrange these problems in a b
2015-03-22 15:21:41
475
原创 快速幂取模模板
用于求解 a 的 b 次方,b是一个非常大的数,可以在O(logn)的复杂度求解。ll pow(ll a,ll b,ll mod){ ll res=1; while(b>0) { if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1; } retu
2015-03-22 15:06:01
448
原创 Ural 1149. Sinus Dances
Let An = sin(1–sin(2+sin(3–sin(4+…sin(n))…)Let Sn = (…(A1+n)A2+n–1)A3+…+2)An+1For given N print SNInputOne integer N. 1 ≤ N ≤ 200OutputLine containing SNSample
2015-01-25 16:27:55
438
原创 hdu 2612 Find a way
Problem DescriptionPass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to meet. Especially a good friend Merceki.Yifen
2015-01-17 15:29:52
322
原创 poj 2923 Relocation
DescriptionEmma and Eric are moving to their new house they bought after returning from their honeymoon. Fortunately, they have a few friends helping them relocate. To move the furniture, they onl
2014-12-01 11:29:58
386
原创 hdu 2639 Bone Collector II
Problem DescriptionThe title of this problem is familiar,isn't it?yeah,if you had took part in the "Rookie Cup" competition,you must have seem this title.If you haven't seen it before,it doesn't m
2014-11-30 15:23:40
533
原创 poj 2184 Cow Exhibition
Description"Fat and docile, big and dumb, they look so stupid, they aren't much fun..." - Cows with Guns by Dana Lyons The cows want to prove to the public that they are both smart and fun
2014-11-30 13:43:49
322
原创 poj1985
DescriptionAfter hearing about the epidemic of obesity in the USA, Farmer John wants his cows to get more exercise, so he has committed to create a bovine marathon for his cows to run. The maratho
2014-11-23 16:02:29
947
原创 poj2251
DescriptionYou are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one un
2014-11-23 13:52:06
335
原创 poj 3278
DescriptionFarmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a pointK
2014-11-22 23:54:24
332
原创 poj 1274
DescriptionN cities named with numbers 1 ... N are connected with one-way roads. Each road has two parameters associated with it : the road length and the toll that needs to be paid for the road (
2014-11-22 21:40:35
335
原创 poj 1088
DescriptionMichael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14
2014-11-22 16:06:35
451
原创 hdu 1172 猜数字
Problem Description猜数字游戏是gameboy最喜欢的游戏之一。游戏的规则是这样的:计算机随机产生一个四位数,然后玩家猜这个四位数是什么。每猜一个数,计算机都会告诉玩家猜对几个数字,其中有几个数字在正确的位置上。比如计算机随机产生的数字为1122。如果玩家猜1234,因为1,2这两个数字同时存在于这两个数中,而且1在这两个数中的位置是相同的,所以计算机会告诉玩家猜对了
2014-11-15 10:54:17
480
原创 hdu 1728 逃离迷宫
Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有些地方是障碍,她必须绕行,从迷宫的一个位置,只能走到与它相邻的4个位置中,当然在行走过程中,gloria不能走到迷宫外面去。令人头痛的是,gloria是个没什么方向感的人,因此,她在行走过程
2014-11-15 10:47:46
717
原创 hdu 1269 迷宫城堡
Problem Description为了训练小希的方向感,Gardon建立了一座大城堡,里面有N个房间(N Input输入包含多组数据,输入的第一行有两个数:N和M,接下来的M行每行有两个数a和b,表示了一条通道可以从A房间来到B房间。文件最后以两个0结束。 Output对于输入的每组数据,如果任意两个房间都是相互连接的,输出"Yes",否则输出"No
2014-10-22 12:49:08
933
原创 杨辉三角
#include #include using namespace std;int main(){ int n, arr[35] = {0}; scanf("%d", &n); for(int i = 1; i <= n; i++) { arr[1] = arr[i] = 1; for(int j = i - 1; j > 1
2014-10-18 20:32:17
353
原创 链式前向星 模板
#include#include#includeconst int maxn = 10005;const int maxm = 1000005;//edgeusing namespace std;int n;struct node{int to,next;// int value ,from,};node edge [maxm];int box[
2014-10-17 16:16:07
525
原创 hdu 2065 "红色病毒"问题
Problem Description医学界发现的新病毒因其蔓延速度和Internet上传播的"红色病毒"不相上下,被称为"红色病毒",经研究发现,该病毒及其变种的DNA的一条单链中,胞嘧啶,腺嘧啶均是成对出现的。现在有一长度为N的字符串,满足一下条件:(1) 字符串仅由A,B,C,D四个字母组成;(2) A出现偶数次(也可以不出现);(3) C出现偶数次(也可以不出现);
2014-10-10 20:45:46
749
原创 STL函数用法
next_permutation 产生全排列的下一个数。调用方法 next_permutation(a,a+n); //n为排列个数
2014-10-10 16:03:23
384
原创 hdu 2063 过山车
Problem DescriptionRPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了。可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个个男生做partner和她同坐。但是,每个女孩都有各自的想法,举个例子把,Rabbit只愿意和XHD或PQK做partner,Grass只愿意和linle或LL做partner,PrincessSnow愿
2014-10-10 15:01:24
619
原创 多校hdu FSF’s game 4944
Problem DescriptionFSF has programmed a game.In this game, players need to divide a rectangle into several same squares.The length and width of rectangles are integer, and of course the side len
2014-10-09 18:14:57
366
原创 判断两条线段是否相交_模版
#include using namespace std; struct point { double x,y; }; struct segment { point begin,end; }; double min(double x,double y) { return x<y?x:y; } double m
2014-10-04 21:27:42
397
原创 hdu 2150 Pipe
Problem Description经过激烈的争夺,Lele终于把那块地从Yueyue的手里抢了回来。接下来,Lele要开始建造他的灌溉系统。通过咨询Lele的好友——化学系的TT,Lele决定在田里挖出N条沟渠,每条沟渠输送一种肥料。每条沟渠可以看作是一条折线,也就是一系列线段首尾连接而成(除了第一条线段开头和最后一条线段的结尾)。由于沟渠很细,你可以忽略掉它的宽度。
2014-10-04 21:19:46
675
原创 Ignatius and the Princess III
Problem Description"Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says."The second problem is, given an positive integer N, we define an
2014-10-04 16:14:08
422
原创 hdu 1022 Train Problem I
Problem DescriptionAs the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is t
2014-10-04 14:51:58
315
原创 卡特兰数
卡特兰数卡特兰数又称卡塔兰数,是组合数学中一个常出现在各种计数问题中出现的数列。由以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名。卡特兰公式的应用很广泛,最典型的四种应用问题现描述如下:1.括号化问题。 矩阵链乘: P=a1×a2×a3×……×an,依据乘法结合律,不改变其顺序,只用括号表示成对的乘积,试问有几种括号化的方案?(h(n)种)
2014-10-04 10:12:22
340
原创 hdu 1026 Ignatius and the Princess I
Problem DescriptionThe Princess has been abducted by the BEelzebub feng5166, our hero Ignatius has to rescue our pretty Princess. Now he gets into feng5166's castle. The castle is a large labyrinth.
2014-09-26 20:33:13
304
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人