
算法码源
文章平均质量分 76
吴钩揽月
这个作者很懒,什么都没留下…
展开
-
hihoCoder之正则表达式
题目:时间限制:1000ms单点时限:1000ms内存限制:256MB描述给定一个字符串,判断其是否为合法的正则表达式。 一个正则表达式定义为: 1:0是正则表达式,1也是正则表达式。 2:P和Q都是正则表达式,则PQ是正则表达式。 3:P是正则表达式,则(P)是正则表达式 4:P是正则表达式,则P*也是正则表达式原创 2015-02-13 16:26:46 · 571 阅读 · 0 评论 -
POJ 1825------Young
问题描述:DescriptionConsider m natural numbers n1, n2, ..., nm with the property n1 >= n2 >= ... >= nm > 0. We define a Young table as an arrangement in a table of n1 + n2 + ... + nm natural原创 2014-12-04 12:16:00 · 2563 阅读 · 0 评论 -
POJ 1508-------Skyscraper Floor
问题描述:Skyscraper FloorsTime Limit: 10000MS Memory Limit: 10000KTotal Submissions: 810 Accepted: 175Description What a great idea it is to build skyscrapers! Using not too large area of la原创 2014-12-03 23:35:01 · 788 阅读 · 0 评论 -
POJ1323------Game Prediction
问题描述:Game PredictionTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 9680 Accepted: 4626DescriptionSuppose there are M people, including you, playing a special card game. At the原创 2014-12-03 23:23:48 · 627 阅读 · 0 评论 -
POJ-1211Traffic Lights
DescriptionOne way of achieving a smooth and economical drive to work is to `catch' every traffic light, that is have every signal change to green as you approach it. One day you notice as you com原创 2014-11-25 18:30:22 · 975 阅读 · 0 评论 -
POJ1100---Dreisam Equations
问题描述:Dreisam EquationsTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 2060 Accepted: 418DescriptionDuring excavations in the Dreisamwuste, a desert on some far away and probabl原创 2014-11-26 16:23:39 · 1171 阅读 · 0 评论 -
POJ1081--You Who?
You Who?Time Limit: 1000MSMemory Limit: 10000KTotal Submissions: 702Accepted: 249Description On the first day of first grade at Friendly Elementrary School, it is customary for each student原创 2014-11-29 12:05:00 · 916 阅读 · 0 评论 -
POJ1400——Complicated Expressions
问题描述:Complicated ExpressionsTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 1503 Accepted: 485Description The most important activity of ACM is the GSM network. As the mobile pho原创 2014-12-01 19:20:26 · 742 阅读 · 0 评论 -
UVA10791----Minimum Sum LCM
问题描述:LCM (Least Common Multiple) of a set of integers is defined as the minimum number, which is a multiple of all integers of that set. It is interesting to note that any positive integer can be原创 2014-11-22 16:44:46 · 525 阅读 · 0 评论 -
UVA138---StreetNumber
问题描述:A computer programmer lives in a street with houses numbered consecutively (from 1) down one side of the street. Every evening she walks her dog by leaving her house and randomly turning left转载 2014-11-22 10:34:42 · 534 阅读 · 0 评论 -
Jugs
UVA 571 Jugs问题描述:In the movie ``Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with the following puzzle. They were given a 3-gallon jug and a 5-gallon jug and were asked to fil原创 2014-11-21 20:28:24 · 906 阅读 · 0 评论 -
POJ 1137----The New Villa
问题描述:The New VillaTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 1354 Accepted: 443Description Mr. Black recently bought a villa in the countryside. Only one thing bothers him:原创 2014-12-05 17:35:29 · 744 阅读 · 0 评论 -
(DAG)NestedRectangle
#include#include#includeusing namespace std;ifstream fin("C:\\data12_1.in");struct rect{rect(int a=0,int b=0):length(a),width(b){}int length;int width;};rect arr[100]转载 2014-11-10 20:41:15 · 565 阅读 · 0 评论 -
heapSort之应用
写了一个类库,有两个版本:版本一:#include#include#includeusing namespace std;template class Schedule{public: Schedule():cnt(0){} ~Schedule(){} type GetMax(); type ExtractMax(); void Insert(type); bo原创 2014-12-24 17:18:29 · 597 阅读 · 0 评论 -
Prim算法
本算法是对《算法导论》相关章节伪代码的实现:这是第一次写的:#include#include#include#includeusing namespace std;#define MAX 32767 ifstream fin("data.in");struct node{ node(int x1,int y1,int len1):x(x1),y(y1),len(原创 2015-01-04 15:38:28 · 620 阅读 · 0 评论 -
POJ 1600 Centipede Collisions
问题描述:DescriptionA small boy named Tommy has some toy centipedes that are a series of 1 centimeter segments. Tommy assembles his centipedes to any length he likes and places them on a 30x30 cen原创 2014-12-09 23:17:53 · 689 阅读 · 0 评论 -
Fibonacci Heap实现
本算法是对<算法导论>相关章节伪代码的实现:先贴代码:#include#include#includeusing namespace std;class FibonacciHeap;class node{ friend class FibonacciHeap; node(int v):key(v),height(0),parent(NULL),left(this),righ原创 2015-01-02 08:40:02 · 795 阅读 · 0 评论 -
binomial heap实现
本算法是对<算法导论>相关章节的实现:下面贴代码:#include#includeusing namespace std;struct node{ node(int d):data(d),degree(0),parent(NULL),child(NULL),sibling(NULL){} int data; int degree; node* parent; node*原创 2014-12-30 18:38:05 · 1065 阅读 · 0 评论 -
Kruskal算法
算法导论第23章第2节#include#includeusing namespace std;struct node{ node(int i,int j,int l):x(i),y(j),len(l){} int x; int y; int len;};int N,M;int u,v,l;node* length[1000];int p[1000];int cnt原创 2014-12-28 15:28:21 · 648 阅读 · 0 评论 -
表达式树及其变体,以及我是如何借着个原理实现简易计算器的功能的
本题来源:《算法竞赛入门》第11章11.11.2本题给的解法:核心代码:int build_tree(string exp,int l,int r){ cout<<"l="<<l<<"\tr="<<r<<endl; int c1,c2,p,u; c1=-1; c2=-1; p=0; if(r-l<=1) { u=++cnt; chl[u]=chr[u]=0;原创 2014-12-11 18:46:55 · 687 阅读 · 0 评论 -
Single-source shortest paths in directed graphs
此算法为<算法导论>中第24章第2小节关于single-source shortest paths in directed graphs原理的实现.原著P592#includeusing namespace std;#define MAX 32767int N,M;int u,v,l,pos;int w[1000][1000],d[1000];int order[1000]原创 2014-12-22 17:21:57 · 600 阅读 · 0 评论 -
Shortest paths and matrix multiplication
本算法是对<算法导论>第25章第一节的实现有三个版本:第一个,普通版本://SLOW-ALL-PAIRS-SHORTEST-PATHS#includeusing namespace std;#define MAX 32767int N,M;int u,v,l;int W[1000][1000],Q[1000][1000],tmp[1000][1000];void p原创 2014-12-26 16:19:48 · 610 阅读 · 0 评论 -
Floyd_Warshall Algorithm
本算法是对算法导论上相关章节伪代码的实现:#include#include#includeusing namespace std;#define MAX 32767ifstream fin("data.in");int N,M;int u,v,l;int D[1000][1000],p[1000][1000],tmpD[1000][1000],tmpP[1000][1000原创 2014-12-27 16:08:13 · 617 阅读 · 0 评论 -
Twin Towers
Problem BThe Twin TowersInput: standard inputOutput: standard output Once upon a time, in an ancient Empire, there were two towers of dissimilar shapes in two different cities. The towers we原创 2014-11-15 18:59:24 · 711 阅读 · 0 评论 -
UVA10006----CarmichaelNumbers
问题描述:An important topic nowadays in computer science is cryptography. Some people even think that cryptography is the only important field in computer science, and that life would not matter at all原创 2014-11-22 12:04:19 · 514 阅读 · 0 评论 -
UVA10673---Play With Floor And Ceil
问题描述:Problem APlay with Floor and CeilInput: standard inputOutput: standard outputTime Limit: 1 second TheoremFor any two integers x and k there exists two more integers p and q such原创 2014-11-22 13:18:42 · 528 阅读 · 0 评论 -
Huffman Codes
#include#include#includeusing namespace std;struct node{ node():frequence(0),ID(' '),left(NULL),right(NULL){} int frequence; char ID; node* left;原创 2014-11-07 20:35:32 · 552 阅读 · 0 评论 -
MidNight'sDream
#include#include#includeusing namespace std;ifstream fin("C:\\data11.in");ofstream fout("C:\\data11.out");int n;int arr[1000000];int equalsum[100];int numkind,totalnum;原创 2014-11-09 15:57:50 · 517 阅读 · 0 评论 -
硬币问题
#include#include#includeusing namespace std;ifstream fin("C:\\data14.in");int n,S;int V[100];int scheme[10000];int value[100];int prev[10000];int trans[10000];void So原创 2014-11-10 15:24:35 · 495 阅读 · 0 评论 -
硬币问题
//此版本和wode#include#include#includeusing namespace std;ifstream fin("C:\\data14.in");int S;int V[1000];int n;int total[1000];int scheme[10000];void Init(){int valu转载 2014-11-11 09:06:10 · 541 阅读 · 0 评论 -
无穷背包问题
#include#include#includeusing namespace std;ifstream fin("C:\\data15.in");int totalVolumn;int weight[100],volumn[100];int n;int scheme[10000];int num[100];void Init()原创 2014-11-11 10:52:26 · 693 阅读 · 0 评论 -
DP入门之一 金字塔
//这个wom#include#include#includeusing namespace std;ifstream fin("C:\\data12.in");int data[32767];int prev[32676];int maxsum[32767];int n;void Init(){fin>>n;in原创 2014-11-10 10:04:17 · 561 阅读 · 0 评论 -
All In All
#include#include#includeusing namespace std;ifstream fin("C:\\data9.in");string s,t;bool IsSubstring(){ int i,j; i=0; for(j=0;j { if(t[j]==原创 2014-11-08 08:20:17 · 541 阅读 · 0 评论 -
Advertisement
#include#include#includeusing namespace std;ifstream fin("C:\\data10.in");struct node{ node(int beg=0,int end=0):startpos(beg),endpos(end){} node& operator=(const n原创 2014-11-08 11:56:54 · 634 阅读 · 0 评论 -
MATRIX_CHAIN
//这是按照算法导论给出解法写出的算法#include#include#includeusing namespace std;ifstream fin("C:\\data17.in");char ID[100];int length[100],width[100];int n;int multinum[100][100];int s[100][100];#define M翻译 2014-11-12 21:17:35 · 639 阅读 · 0 评论 -
带宽
//此代码为中级版,尚待修改#include#include#include#includeusing namespace std;ifstream fin("C:\\data4.in");ofstream fout("C:\\data4.out");int COUNT=0;char node[8]原创 2014-11-06 17:58:08 · 584 阅读 · 0 评论 -
(GAD)NestedRectangle
//同样k#include#include#includeusing namespace std;ifstream fin("C:\\data13.in");struct rect{rect(int a=0,int b=0):length(a),width(b){}int length;int width;};rect原创 2014-11-10 14:13:14 · 591 阅读 · 0 评论 -
区间选点
//此为按贪心算法得出的一种su原创 2014-11-06 19:16:07 · 613 阅读 · 0 评论 -
棋盘覆盖
#include#include#include#include#includeusing namespace std;#define _DEBUG#ifdef _DEBUGifstream fin("C:\\data5.in");ofstream fout("C:\\data5.out");#原创 2014-11-06 17:59:21 · 540 阅读 · 0 评论 -
最小最大值
#include#include#includeusing namespace std;ifstream fin("C:\\data6.in");int arr[32767];int cnt;int m;int sum;int cn=0;void Init(){ int x; cnt=0; su原创 2014-11-06 17:56:00 · 570 阅读 · 0 评论