上一页 1 2 3 4 5 6 7 8 ··· 57 下一页

2011年8月30日

sicily 1800. Sequence

摘要: // 题意: 给出一个序列,求一段连续区间内元素的和的最小值,区间的长度范围[L,U]// 思路: sum[i]记录原序列从1到i的元素的和, 枚举下标 i , // 求出以 i 为结尾,区间长度范围从 L 到 U 的连续和的最小值,// 这可以通过找出sum[i-U]-sum[i-L]中的最大值MAX,则sum[i]-MAX 取得最小值#include <iostream> //线段树#include<cstdio>using namespace std;int sum[40000],MAX; //sum[i]指原序列从1到i的元素的和struct seg... 阅读全文

posted @ 2011-08-30 16:16 sysu_mjc 阅读(188) 评论(0) 推荐(0) 编辑

sicily 1198. Substring

摘要: #include<iostream> #include <string>#include<cstdio>using namespace std;int main(){ int T,N,l,i,j; string str[8]; cin>>T; for(l=0;l<T;l++) { scanf("%d",&N); for(i=0;i<N;i++) cin>>str[i]; for(i=0;i<N;i++) for(j=i+1;j... 阅读全文

posted @ 2011-08-30 11:30 sysu_mjc 阅读(214) 评论(0) 推荐(0) 编辑

2011年8月24日

以数组方式建立二叉树

摘要: sicily 1156//结点以0到1000标识,存储在数组tree[1001]中,这样就可以不用按遍历或按层遍历的方法来建立二叉树了,随时都可以插入一结点#include<iostream>#include<stack>#include<memory.h>using namespace std;int isroot[1001];bool had[1001];struct node{ char c; int l;int r;}tree[1001];void init(){ for (int i=0;i<=1000;i++) tree[i].l=tree 阅读全文

posted @ 2011-08-24 21:15 sysu_mjc 阅读(295) 评论(0) 推荐(0) 编辑

图的关键路径

摘要: #include <iostream>using namespace std; //边表示活动的网AOE网,是基于假设:活动可以并行地进行,即从某顶点出发的几条边可以同时进行const int MaxVertex=10;const int MaxEdge=50;struct Edge { int index; //邻接顶点的下标,表示第index个顶点 int weight; Edge *next;};struct item //表头结点结构{ int data; //顶点数据 ... 阅读全文

posted @ 2011-08-24 21:12 sysu_mjc 阅读(382) 评论(0) 推荐(0) 编辑

森林

摘要: //sicily 1034. Forest// 1.如果有任一节点的入度>1 或者没有根节点,则不是森林,否则:// 2.先找根节点(入度为0的节点),压入栈.// 3.对栈中的根结点(当前)删除掉,把所有子节点压入栈,重复这过程.最后若所有结点都曾压入栈中,则能构成森林,反之则说明有环存在#include<iostream> //BFS求森林深度和宽度 #include<stdio.h>#include<vector>#include<stack>#include<cstring>using namespace std;str 阅读全文

posted @ 2011-08-24 16:32 sysu_mjc 阅读(229) 评论(0) 推荐(0) 编辑

邻接链表

摘要: //sicily 1024. Magic Island#include<iostream>#include<cstring>using namespace std;struct Edge{ int v,w; int next;}edge[20010];int head[10010],curr,vis[10010],res;void add_edge(int x,int y,int d) //读入的边插入到图的邻接链表{ edge[curr].v=y;edge[curr].w=d; edge[curr].next=head[x]; head[x]=curr; ... 阅读全文

posted @ 2011-08-24 16:31 sysu_mjc 阅读(680) 评论(0) 推荐(0) 编辑

哈夫曼树

摘要: #include <iostream>#include <iomanip>#include <string>using namespace std;typedef int ElementType;struct HuffNode { ElementType data; //data表示权值数据域 int par; //par=0表明结点是独立的,par>0为它的双亲下标 int lch,rch; //lch,rch左右孩子结点在数组中的下标,0,0则表示它是独立结点};const int MAXSIZE... 阅读全文

posted @ 2011-08-24 16:28 sysu_mjc 阅读(285) 评论(0) 推荐(0) 编辑

二叉树之三

摘要: #include<iostream> #include<stack>#include <queue>using namespace std;struct BiNode{ char data; BiNode *LChild; BiNode *RChild; int ltag;int rtag;};void Creat(BiNode *root) //先序建立{ char ch; cin>>ch; if(ch=='#'){root->data=ch;root->ltag=root->rtag=0;} //#代表... 阅读全文

posted @ 2011-08-24 16:27 sysu_mjc 阅读(171) 评论(0) 推荐(0) 编辑

二叉树之二

摘要: //sicily 1156. Binary tree#include<iostream> //给出一棵二叉树,输出前序遍历序列#include<stack>using namespace std;struct node{ char c; int l,r;}tree[1010];int vis[1010],rt[1010];void add(int p,char c,int l,int r) //满足vis[p]==1且rt[p]==1 是根结点{ tree[p].c=c; vis[p]=1; if(l>0) { tr... 阅读全文

posted @ 2011-08-24 16:26 sysu_mjc 阅读(168) 评论(0) 推荐(0) 编辑

二叉树之一

摘要: //sicily 1935. 二叉树重建#include <iostream> //根据先序遍历序列和中序遍历序列建立二叉树,并按层遍历#include <string>using namespace std;string str1,str2;int n;struct Node { char ch; Node *left,*right;}node[5000];Node* built(int s1,int t1,int s2,int t2) //根据先序遍历序列和中序遍历序列建二叉树{ int m=n++; //声明为局部变量 n... 阅读全文

posted @ 2011-08-24 16:25 sysu_mjc 阅读(130) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 8 ··· 57 下一页

导航