数据结构
数据结构
kelianlee
这个作者很懒,什么都没留下…
展开
-
Not so Mobile UVA - 839(递归)
#include <iostream> using namespace std; bool solve(int& w) { int w1,r1,w2,r2; cin>>w1>>r1>>w2>>r2; bool t1=true,t2=true; if(!w1) t1=solve...原创 2019-01-31 13:29:44 · 126 阅读 · 0 评论 -
Tree UVA - 548(中序后序建树)
后续遍历的最后一个数字就是根节点所以用递归把一棵树的子树看成单独的一棵树就能用递归建树了 #include <iostream> #include <stdio.h> #include <string> #include <sstream> #include <algorithm> using namespace std; const...原创 2019-01-31 11:53:46 · 148 阅读 · 0 评论 -
Trees on the level UVA - 122(层序遍历bfs)
#include <iostream> #include <cstdio> #include <vector> #include <queue> #include <cstring> using namespace std; struct Node{ int v; Node* left ,*right; in...原创 2019-01-30 19:49:51 · 105 阅读 · 0 评论 -
Dropping Balls UVA - 679(找规律)
把每个点看成两部分左子树与右子树 #include <iostream> using namespace std; int main() { int n; while(scanf("%d",&n)&&n!=-1) { int a,b; for(int i=0;i<n;i++) ...原创 2019-01-30 17:36:17 · 124 阅读 · 0 评论 -
Knight Moves UVA - 439(BFS最短路)
#include <iostream> #include <queue> #include <cstring> using namespace std; int vis[11][11]; int mx[8]={1,2,2,1,-1,-2,-2,-1}; int my[8]={2,1,-1,-2,-2,-1,1,2}; struct node { ...原创 2019-02-10 13:40:32 · 109 阅读 · 0 评论 -
Boxes in a Line UVA - 12657(双链表)
#include <iostream> using namespace std; typedef long long ll; const int MAXN=100000+10; int Left[MAXN],Right[MAXN]; void link(int l,int r) { Left[r]=l; Right[l]=r; } int main() {...原创 2019-01-30 15:26:33 · 144 阅读 · 0 评论 -
Tree Recovery UVA - 536(前序中序构建树)
#include <iostream> #include <string> using namespace std; const int MAXN=111; char l[MAXN],r[MAXN]; string a,b; char build(int l1,int r1,int l2,int r2) { if(l1>r1) retu...原创 2019-02-09 21:34:50 · 132 阅读 · 0 评论 -
Broken Keyboard (a.k.a. Beiju Text) UVA - 11988(链表)
链表模拟 #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> using namespace std; char s[101000]; int Next[101000]; int main() { int cur,last;//cur为...原创 2019-01-30 14:02:13 · 216 阅读 · 0 评论 -
Parentheses Balance UVA - 673(括号匹配栈)
#include <iostream> #include <cstring> #include <string> using namespace std; const int MAXN=111111; string str[MAXN]; int cont=0; bool islable( char c ) { if( c == ' ' || c...原创 2019-02-08 19:57:52 · 137 阅读 · 0 评论 -
Ordering Tasks UVA - 10305(拓扑排序dfs)
#include <iostream> #include <cstring> using namespace std; const int MAXN=111; int map[MAXN][MAXN]; int vis[MAXN]; int stack[MAXN]; int top; int n,m; void dfs(int t) { vis[t]=-1; ...原创 2019-02-03 22:30:24 · 147 阅读 · 0 评论 -
The Falling Leaves UVA - 699(递归map)
#include <iostream> #include <map> using namespace std; map<int,int>mp; int cont=0; void tree(int n) { int t; cin>>t; if(t==-1) return ; mp[n]+=t; ...原创 2019-01-31 22:58:51 · 110 阅读 · 0 评论 -
L3-010 是否完全二叉搜索树(完全二叉树)
注意对完全二叉树的定义判断 #include<cstdio> #include<cstring> #include<queue> using namespace std; int s[500]; void insert(int r,int a) { if(s[r]==-1) { s[r]=a; return; } if(s[r]<a...原创 2019-03-31 16:16:22 · 166 阅读 · 1 评论