随笔分类 -  数据结构

摘要:#include #include using namespace std;int main(){ stack s; char a[100],b[100]; int i,j,n,l,f[100]; while(cin>>n>>a>>b) { l=0; i=0; j=0; s.push(a[i]); f[l++]=1; while(i<n&&j<n) { if(s.size()&&s.top()==b[j]) { s.pop(); j++; f[l++]=0; }else{ s.push(a[++i]); f[l++ 阅读全文
posted @ 2014-03-11 17:06 shijiwomen 阅读(476) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <malloc.h>int n,m,c;struct node{ int data; struct node * next;};void InitList(node * H){ H=(node *)malloc(sizeof(node)); H->next=NULL;}void CreateFromHead(node * H){ node *s; node *r; r=H; for(int i=1;i<=n;i++) { s=(node *)malloc(sizeof(node)); s->data 阅读全文
posted @ 2012-04-27 20:40 shijiwomen 阅读(262) 评论(0) 推荐(0)
摘要:其中巧妙的运用了优先队列,将哈夫曼树的精髓给表达了出来需要注意的是其中的优先队列的定义,一定要有自定义比较#include <iostream>#include <cstdio>#include <queue>using namespace std;struct node{ __int64 value; bool operator <(const node &a)const { return value>a.value; }}temper;int main(){ priority_queue<node> qu; int i,n 阅读全文
posted @ 2012-04-06 11:26 shijiwomen 阅读(227) 评论(0) 推荐(0)
摘要:dp主要是找到状态方程,大多运用双层循环,进行整体最优解的积累,像数塔,时间安排比较困难的就需要循环加条件判断比较,还有比较需要熟悉的是一般都是先从后往前递归出方程,在进行递推编码#include <stdio.h>int main(){ int i,j; int n,c,t; int vt,v1,v2; int len; int p[102]; double e,min,dp[102]={0}; while(scanf("%d",&len)!=EOF) { scanf("%d%d%d",&n,&c,&t); 阅读全文
posted @ 2012-03-28 22:31 shijiwomen 阅读(238) 评论(0) 推荐(0)