摘要: 树状数组,因为此是求二维数组的区间的和,所以将其扩展为二维树状数组#include <stdio.h>#include <memory.h>const int maxn=1100;int c[maxn][maxn];int n;int LowBit(int x){ return x&(x^(x-1));}void Update(int x,int y,int a){ for(int i=x;i<=n;i+=LowBit(i)) for(int j=y;j<=n;j+=LowBit(j)) c[i][j]+=a;}int getSum(int x,in 阅读全文
posted @ 2012-10-14 15:59 lishimin_come 阅读(88) 评论(0) 推荐(0) 编辑
摘要: 欧拉回路+并查集(判断图的联通)+Tire树(快速查找字符串,并且记录相应点的度数)Tire树相关知识http://zh.wikipedia.org/wiki/Trie#include <iostream> using namespace std; const int maxc = 26; const int maxn = 500001; struct TrieNode { int key; TrieNode * child[maxc]; TrieNode() { key=-1; memset(child,0,sizeof(child)); } }; int count[ma... 阅读全文
posted @ 2012-10-12 19:47 lishimin_come 阅读(103) 评论(0) 推荐(0) 编辑
摘要: 题不难,数据结构之BST,就是输入纠结了一会#include <iostream> #include <cstring> using namespace std; const int maxn=30; struct Tnode { char data; Tnode * lchild; Tnode * rchild; }; Tnode * root; void insert(Tnode * p,char c) { if(root==NULL) { root=new Tnode; root->data=c; root->lchild=NULL; root-> 阅读全文
posted @ 2012-10-09 23:17 lishimin_come 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 线段树,顺序存储实现#include <stdio.h> #include <string.h> const int maxx=32000; const int maxn=15000; int l[3*(maxx+1)],h[3*(maxx+1)],w[3*(maxx+1)]; int N; int ans[maxn]; void Create(int t,int s,int f) { l[t]=s;h[t]=f; if(s<f) { int mid=(s+f)/2; Create(2*t+1,s,mid); Create(2*t+2,mid+1,f); } } 阅读全文
posted @ 2012-09-29 14:22 lishimin_come 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 刚看了这道题目完全没思路,在网上找了结题报告,了解到需用离散化+线段树+扫描,但菜鸟一个,发现数据规模并不大,用离散化完全可以,所以只用了离散化,思路还是很清晰的,但还是贡献了5个小时,15次wa,纠结过后发现x,y数组我是从1开始计数的,但sort 的时候却是从0开始sort,结果导致身心煎熬了n小时,粗心惹的祸啊//离散化求解!!!!#include <iostream>#include <algorithm>using namespace std;const int maxn=210;double x[maxn],y[maxn];int vis[maxn][max 阅读全文
posted @ 2012-09-25 15:17 lishimin_come 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 第一道并查集,47ms ,还是很慢啊,不过是绞尽脑汁,调试了n次,做出来的,思路还是挺清晰地#include <iostream> using namespace std; const int maxn=30010; int parent[maxn]; int amount[maxn]; int rank[maxn]; int n,m; void init() { for(int i=0;i<n;i++) { parent[i]=i; amount[i]=1; rank[i]=0; } } int find(int t) { if(parent[t]!=t) retur... 阅读全文
posted @ 2012-09-23 20:16 lishimin_come 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 二分#include <iostream> using namespace std; const int maxn=5010; int Ui[maxn],Li[maxn],dx[maxn],dy; int amount[maxn]; int m,n,x1,y1,x2,y2; int bsearch(int xj,int yj) { int low=-1,high=m,mid; while(high-low>1) { mid=(high+low)/2; if((dy*(xj-Ui[mid])-dx[mid]*(yj-y1))<0) high=mid; else lo... 阅读全文
posted @ 2012-09-22 16:00 lishimin_come 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 注意的情况比较多,尤其是空树这一种#include <iostream> #include <stdlib.h> using namespace std; const int maxn=100; struct node { int s,f; node* next; };//在此数据结构采用链表,方便后续遍历算法 int indexNode[maxn];//用于构造索引的数组 int v[maxn]; node *head; int totNode;//节点的总数 void visitNode(int temNode) { node* p=head->next; v 阅读全文
posted @ 2012-09-18 19:00 lishimin_come 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 知识点:栈的应用语法经验,主函数外的函数中的指针变量不能付给主函数中的指针,因为函数调用完后就会释放内存,赋值相当于没赋#include<iostream>using namespace std;const int maxn=110;void trans(char *exp,char *atexp);int oc( char *s);int main(){ int t=1,jud; char exp[maxn]; char atexp[maxn]; while(cin.getline(exp,maxn)) { trans(exp,atexp); jud=oc(atexp); cha 阅读全文
posted @ 2012-09-15 20:50 lishimin_come 阅读(190) 评论(0) 推荐(0) 编辑
摘要: 本题目的dfs原理不难,个人认为难点式路径的记录,刚开始定义了很大的数组,提交的时候超出了内存的限制,后来在网上发现有的人用了栈存储,纠结了半天终于搞出来啦。#include <stdio.h> #include <string.h> int flag; int st[7]; int head; int in[6]; int digit; int digit2; int num1,max; int de; void dfs(int cur,int sum) { if(cur>=digit2) { if(sum>max) { max=sum; flag=1; 阅读全文
posted @ 2012-07-02 11:41 lishimin_come 阅读(154) 评论(0) 推荐(0) 编辑