遞迴求二叉樹的高度

用遞迴求樹的高度,哎。。。平時很少用指標,寫起來挺吃力的#include<stdio.h>#include<string.h>#include<stdlib.h>typedef struct bnode{char data;struct bnode *lchild,*rchild;}btnode;int max(int x,int y){return x>y?x:y;}btnode *create() //建樹{char c;btnode

HDU-2553-N皇后問題

HDU-2553-N皇后問題http://acm.hdu.edu.cn/showproblem.php?pid=2553基本的DFS,感覺DFS就像求全排列一樣#include<stdio.h>#include<string.h>#include<stdlib.h>int n,ans;int map[15];int visit[15];int sol[15];void dfs(int k){int

HDU-1016-Prime Ring Problem

HDU-1016-Prime Ring Problemhttp://acm.hdu.edu.cn/showproblem.php?pid=1016基本的DFS,先打個素數表即可#include<stdio.h>#include<string.h>#include<stdlib.h>int prime[50];int visit[30];int num[30];int n;void init(){ int i,j;

HDU-1225-Football Score

HDU-1225-Football Scorehttp://acm.hdu.edu.cn/showproblem.php?pid=1225終於放假了,在家就是舒服,網速也變成4M的了,好爽哇這題就是字串的類比,注意細節就好#include<stdio.h>#include<string.h>#include<stdlib.h>int n,t;struct cam{ char str[50]; //隊名int score1; //得分int score2; //

NYOJ-35-運算式求值

NYOJ-35-運算式求值http://acm.nyist.net/JudgeOnline/problem.php?pid=35 很好的一題,利用棧來計算運算式的值四則運算的規則:1.先乘除,後加減;2.從左算到右;3.先括弧內,後括弧外注意把字串轉換成浮點數可以使用atof函數#include<stdio.h>#include<string.h>#include<stdlib.h>int map[7][7]=

ZOJ-3633-Alice’s present

ZOJ-3633-Alice's presenthttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3633給定一個序列,每次詢問一個區間內,從右往左看,第一個重複的線段樹,這題做了好長時間,感謝cxlove牛用一個數組標記和當前數字相等的最右邊的數位位置,若沒有則記為-1,比如1 2 3 1 2 3這段數對應的標記數組為-1 -1 -1 1 2

九度OJ-1172-哈夫曼樹

九度OJ-1172-哈夫曼樹http://ac.jobdu.com/problem.php?pid=1172哈夫曼樹(Huffman tree):給定n個權值作為n個葉子結點,構造一棵二叉樹,若帶權路徑長度達到最小,稱這樣的二叉樹為最優二叉樹,即哈夫曼樹這題可以建樹,也可以不建樹。建樹:#include<stdio.h>#include<string.h>#include<stdlib.h>#define maxvalue 0x7fffffffstruct

ZOJ-3635-Cinema in Akiba

ZOJ-3635-Cinema in Akibahttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4803有n個從1..n標號的座位,按時間順序給出每個客人來的時候是坐在第幾個空座位,最後給若干個詢問問第i號客人坐在哪裡線段樹即可,和POJ-2828-Buy

POJ-1486-Sorting Slides

POJ-1486-Sorting Slideshttp://poj.org/problem?id=1486給出一些矩形的座標和一些點的座標,若點在矩形內,則該點和該矩形匹配,問是否存在某個匹配在所有的完美匹配中,這題可以先任意找出一個完美匹配,然後依次刪除該匹配的每一條邊,若仍能構成完美匹配,則這個匹配不唯一,若不能構成完美匹配,則該匹配唯一#include<iostream>#include<cstdio>#include<cstring>#include&

ZOJ-3641-Information Sharing

ZOJ-3641-Information

HDU-1195-Open the Lock

HDU-1195-Open the Lockhttp://acm.hdu.edu.cn/showproblem.php?pid=1195基本的BFS,對一個四位元,任選一位加1或減1,或交換相鄰的兩個數#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<queue>#include<cmath>using

ZOJ-3642-Just Another Information SharingProblem

ZOJ-3642-Just Another Information

HDU-4287-Intelligent IME

HDU-4287-Intelligent IMEhttp://acm.hdu.edu.cn/showproblem.php?pid=4287開始用字典樹+深搜,逾時。。。。後來發現題目最多6位元,可將字串轉化成對應的數字,然後hash即可TLE的代碼#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> using namespace std;

POJ-2060-Taxi Cab Scheme

POJ-2060-Taxi Cab

ZOJ-3640-Help Me Escape

ZOJ-3640-Help Me Escapehttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3640一隻吸血鬼,有n條路給他走,每次他隨機走一條路,每條路有個限制,如果當時這個吸血鬼的攻擊力大於等於某個值,那麼就會花費t天逃出去,否則,花費1天的時間,並且攻擊力增加,問他逃出去的期望#include<iostream>#include<cstdio>#include<cstring>#

HDU-1501-Zipper

HDU-1501-Zipperhttp://acm.hdu.edu.cn/showproblem.php?pid=1501基本的DFS,注意搜尋過的狀態要標記,不然會逾時#include<stdio.h>#include<string.h>#include<stdlib.h>char str1[205],str2[205],str3[405];int flag;int len1,len2,len3;int hash[205][205];void

POJ 2352 Stars (樹狀數組)

/* Memory: 508K Time:641MS Sumraize:第一次接觸樹狀數組,感覺好難,光是在wiki上理解理論知識就花了大半天... 代碼是看了別人AC代碼的copy的..天,為我捉急!*/#include <iostream>#include <algorithm>using namespace std;#define MAX 32005int lev[MAX];int tree[MAX];int read(int idx)

HDU-1565-方格取數(1)

HDU-1565-方格取數(1)http://acm.hdu.edu.cn/showproblem.php?pid=1565我的第一個狀態壓縮DP給你一個n*n的格子的棋盤,每個格子裡面有一個非負數,從中取出若干個數,使得任意的兩個數所在的格子沒有公用邊,就是說所取的數所在的2個格子不能相鄰,並且取出的數的和最大375 15 21 75 15 28 34 70

HDU-1074-Doing Homework

HDU-1074-Doing

HDU-1520-Anniversary party

HDU-1520-Anniversary partyhttp://acm.hdu.edu.cn/showproblem.php?pid=1520DFS,有些節點具有父子關係,要求具有父子關係的節點不能同時出現#include<iostream>#include<cstdio>#include<cstring>#define N 6001struct node //左二子右兄弟法建樹{ int parent; int child; int

總頁數: 61357 1 .... 13473 13474 13475 13476 13477 .... 61357 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.