uva .datastructure.binary tree

the first problem is 112.It's a complicated problem but not hard.We can deal with the input  firstly,put all the valid character into a string and we can use a var "pair" substitute the

8.2 sum

3.【最大連續和】sum【題目描述】輸入一個長度為n的整數序列(A1,A2,……,An),從中找出一段連續的長度不超過M的子序列,使得這個序列的和最大【輸入格式】第一行兩個數n,m接下來n行,每行一個數ai。【輸出格式】一行,最大的滿足條件的連續的長度不超過M的子序列。【資料範圍】30%的資料:n<=3000,m<=100100%的資料N,M<=1000000,-maxlongint<=ai<=maxlongint【範例輸入】4 2-1 3 –10 20【範例輸出】

uva 839 439 784

先講839,這是binary tree裡面的題,是判斷樹的節點重量是否平衡,解題接的我快無語了,先是看錯提, 後來又做錯,再後來是re,最後,明白了,遍曆可以跟建樹結合,這樣就不會棧溢出,因為如果你先建樹(遞迴),再遍曆又遞迴是很容易溢出的,反正遞迴棧總有要返回的,所以乾脆一邊建樹,一邊解答,具體的看代碼://#define

8.2 minval

4.【最小函數值】minval 【題目描述】    有n個函數,分別為F1,F2,...,Fn。定義Fi(x)=Ai*x^2+Bi*x+Ci(x∈N*)。給定這些Ai、Bi和Ci,請求出所有函數的所有函數值中最小的m個(如有重複的要輸出多個)。【輸入格式】    第一行輸入兩個正整數n和m。    以下n行每行三個正整數,其中第i行的三個數分別為Ai、Bi和Ci。輸入資料保證Ai<=10,Bi<=100,Ci<=10 000。【輸出格式】   

uva 673

題目類型:棧題目描述:括弧匹配經曆:杯具,WA了數次,原因:Yes,No我寫成YES,NO。。。。。。心得:1要小心輸出。。。。         2變數最好初始化代碼:#include<stdio.h>#include<string.h>char  s[150];int top=0;int pop(char &x){ if(top==0)return 0; x=s[--top]; return 1;}int push(char

8.3 心疼

Problem  1  heart.pas/c/cpp(heart.in   heart.out)     【背景】 

uva 10004 10596 10305 10054 10129 327 532

10004 深度搜尋,將邊兩邊的點賦值為不同顏色(bool類型),因為是強聯通圖,所以只需一次就夠,判斷是否存在有向環以及該有向環是否是否滿足點顏色相同,#include<cstdio>#include<cstdlib>#include<string>#include<cmath>using namespace std;const int maxn=205;int

uva 621

題目類型:判斷無聊的水題。。。1AC唯一迷惑的地方:譬如94有輸出,儘管題目說9S4,但S可以是空的,大概除此之外,真的沒有其他的代碼:#include<stdio.h>#include<string.h>int main(){ char s[1000]; int n; scanf("%d",&n); for(int i=0;i<n;i++) {  scanf("%s",s);     int

uva 10152

題目類型:線性排序解題過程:這道題思路是參考knowledgetime的,後來自己用數學歸納法證明了一下演算法正確性,杯具的是太久沒做題,竟然又忘了scanf與輸入字串時要加getchar();好噁心,弄了好久。。。題目:給出一序列字串,再給出目標序列,要求,每次只能將源序列中的字串置頂,輸出:最少操作時應該置頂的字串解題:等同於:這題就是發現規律,通過棧區去實現。第前n個輸入時不做任何處理。後n個輸入要尋找對應前n個的相應位置。然後從底往上找到第一個比下層大的,然後從這個一直相應輸出前n個名字

QT4.5移植

 qt-embedded-linux-opensource-src-4.5.1移植到QQ2440開發板 http://www.cnblogs.com/cnnbboy/archive/2009/06/06/1497780.html前言:非常漫長的過程,可以說,移植qte4.5.1是我移植qte以來最難的一次,前面幾次都非常順利的完成了,這次卻花了很大的力氣,期間得到了阿樂的大力協助,可以說移植完成,是我們兩個人的汗血啊。摘要:在友善之臂QQ2440

uva 10763

問題描述:給出n個二元組(Oi,Ti),看看能否一一對應,即(Oi,Ti)---(Ti,Oi),能yes,否no舉例:31 22 11 2no41 22 11 22

uva 10161

題目類型:數學,數論心得:找規律,打表代碼:#include#include#includeint main(){ long n,row,column;while(scanf("%d",&n)==1){row=column=0;if(n==0)break;long k=0;k=(long)(sqrt(n)+0.5);if(k*k>n)k=k-1;if(k*k==n){if(k%2){row=1;column=k;}else

uva 573

題目類型:數學解題思路:類比就行了解題心得:理解好題意代碼:#include<stdio.h>#include<math.h>#define eps 1e-9int main(){int H,U,D,F;while(scanf("%d%d%d%d",&H,&U,&D,&F)==4){if(!H ) return 0;double climb=U,slide=D,cur=0,s;int

uva 10594

問題描述:計算一次加法的代價為兩個加數的和,求計算一條加法公式的總代價類型:哈弗曼演算法解法:用兩個隊列類比哈弗曼即可,或者優先隊列?#include<cstdio>#include<cstdlib>#include<string>#include<algorithm>using namespace std;const int MAXSIZE=500001; long long P[MAXSIZE],Q[MAXSIZE]; int

次優尋找樹(爛版本)

#include<stdio.h>#include<math.h>#include<string.h>#define eps 1e-9typedef struct TNode{char data;struct TNode *left,*right;}Node;Node nodes[10000];Node *root;char key[1000+10];int tk=0;void SecondOptimal(Node * &T,char

uva 10499

題目類型:數學解題過程:題目很簡單,但噁心的精度問題,沒考慮,最終延續杯具曆史。。。千萬不能用整形輸出原因:題目的N可能為2^31-1,所以。。。。解題心得:要注意範圍,還有邊界 最後:#include<stdio.h>#include<math.h>#define eps 1e-9int main(){int n;while (scanf("%d",&n)==1){if(n<0) return 0;if(n==1 || n==0 ){printf("0%%

UVa Problem Solution: 120 – Stacks of Flapjacks

I just simulate the flipping. We are not required to find the optimal solution, so I choose a way easy to understand. I find the biggest cake in the unsorted stack, and then check its position. If it is at the bottom of the stack, then nothing need

UVa Problem Solution: 848 – Fmt

At the first look, this problem seems to be tricky to solve. However, if you implement all the specifications precisely, it would be already solved. There's no need to "translate" the problem's specifications.Code:/***********************************

uva 10130

問題描述:幾個人的01背包問題問題解法:看看147那道,就知道一樣的#include<cstdio>#include<cstdlib>#include<string>using namespace std;const int maxp=105*1000;const int maxn=1001;int v[105];long long d[maxp];int p[maxn],w[maxn];int main(){ int S,n; int

UVa Problem Solution: 10041 – Vito’s Family

Vito should live on the street which is the median of his

總頁數: 61357 1 .... 21751 21752 21753 21754 21755 .... 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.