Time of Update: 2018-12-05
題目來源:http://acm.pku.edu.cn/JudgeOnline/problem?id=1521 解題報告: 典型HUFFMAN樹的問題,用了STL的priority_queue,調了一下午,鬱悶 #include <iostream>#include <string>#include <queue>using namespace std;class node{public:int key; //a,b,c...int count;//頻率int
Time of Update: 2018-12-05
DescriptionMichael喜歡滑雪百這並不奇怪, 因為滑雪的確很刺激。可是為了獲得速度,滑的地區必須向下傾斜,而且當你滑到坡底,你不得不再次走上坡或者等待升降機來載你。Michael想知道載一個地區中最長底滑坡。地區由一個二維數組給出。數組的每個數字代表點的高度。下面是一個例子 1 2 3 4 516 17 18 19 615 24 25 20 714 23 22 21 813 12 11 10 9一個人可以從某個點滑向上下左右相鄰四個點之一,若且唯若高度減小。在上面的例子中,
Time of Update: 2018-12-05
第十七章 平攤分析 總結:平攤分析是一種用來分析執行一系列類似操作的演算法的工具,它對整個操作序列的真實代價限界。本章介紹了平攤分析的三種方法,分別是聚集分析、記賬方法、勢能方法。每種方法都通過分析棧操作和二進位計數器增1來舉例分析。最後,本章用平攤分析的方法分析了表動態擴張和收縮的代價限界。 1. 聚集分析證明對所有的n,有n個操作所構成的序列的總時間在最壞情況下為T(n)。因此,每個操作的平均代價為T(n)/n 2.
Time of Update: 2018-12-05
題目來源: http://acm.pku.edu.cn/JudgeOnline/problem?id=3267 解題報告:
Time of Update: 2018-12-05
題目來源:http://acm.pku.edu.cn/JudgeOnline/problem?id=1012今天第一次嘗試做ACM的題,挑了道看似最簡單的Joseph題做,誰知道過程很坎坷啊,提交了n次,終於搞定了。首先,我常試用一個迴圈鏈表的方式做代碼如下:#include <iostream>#include <vector>using namespace std;class node{public:int data;node
Time of Update: 2018-12-05
A.Even Odds 給你n和k, 把從1到n先排奇數後排偶數排成一個新的序列,輸出第k個位置的數。比如 10 3 拍好後就是 1 3 5 7 9 2 4 6 8 10 第3個數是5。//cf 318 A//2013-06-18-20.30#include <iostream>using namespace std;int main(){ __int64 n, k; while (cin >> n >> k) {
Time of Update: 2018-12-05
數學 打了個表 找一下規律....#include <cstdio>int a[30];void init(){ a[1]=2;a[2]=4;a[3]=8;a[4]=16;a[5]=32;a[6]=64;a[7]=128;a[8]=256;a[9]=512;a[10]=1024;a[11]=2048;a[12]=4096;a[13]=8192;a[14]=16384;a[15]=32768;a[16]=65536;a[17]=131072;a[18]=262144;a[19]=
Time of Update: 2018-12-05
題目來源:https://www.interviewstreet.com/challenges/dashboard/#problem/4fffc24df25cd解題報告:這道題求一顆樹,最多可以去掉幾條邊,使得被分割成的每顆單獨的樹的節點個數都是偶數。題目蠻有意思,難度適宜。首先,將輸入轉換為樹的格式,對每個節點,保留它的父親節點和兒子節點的編號。然後遍曆樹的每個節點,得到以該節點為根的樹的節點個數(包括該節點)對一個節點R,設它有兒子節點A,如果以A為根的樹的節點個數有偶數個,則代表R與A這條
Time of Update: 2018-12-05
題目來源:https://www.interviewstreet.com/challenges/dashboard/#problem/4edb8abd7cacd解題報告:簡單的字串處理,對S的每個尾碼,計算它與S的相似性,相似性計算是用遞迴做的。#include <iostream>#include <string.h>using namespace std;int getSim(char* str1, char* str2){ if ( *str1 == '\0'
Time of Update: 2018-12-05
c.front() 返回第一個元素 c.back() 返回最後一個元素 c.push_back(e) 在尾部插入元素e c.pop_back() 刪除最後一個元素 c.clear() c.erase(pos) 刪除pos位置的元素 c.erase(beg,end) 刪除區間[beg,end] 內的元素
Time of Update: 2018-12-05
貪心,讓時間少的漢堡數量盡量多。#include<cstdio>#include<iostream>#include<cstring>#include<cstdlib>#include<algorithm>#include<set>#include<vector>using namespace std;int main(){ //freopen("in.txt","r",stdin);
Time of Update: 2018-12-05
一開始題意理解錯了,不一定是連續的子序列,只要是升序就可以,理解題意後,以為兩個迴圈枚舉起點就可以了,於是寫了下段代碼:#include<cstdio>#include<iostream>#include<cstring>using namespace std;int main(){ freopen("in.txt","r",stdin); int n,num[1010],cur; long long int
Time of Update: 2018-12-05
竟然1Y, 竊喜啊,本來以為很麻煩,怎樣碰撞才能使時間儘可能長呢?後來自己出了幾組資料,發現最長時間就是最靠繩端的螞蟻向另一端運動的時間。試著寫了寫代碼交上竟然過了,查了一下題解,其實碰撞後反向運動就是相當於保持原方向運動,因為螞蟻移動速度是一樣的。而所求的是所有螞蟻都運動到繩子端點的時間。#include<cstdio>#include<cstring>#include<iostream>using namespace std;int
Time of Update: 2018-12-05
把相關聯的兩個點記下來,然後dfs.這個題n是5*10^4,無法開一個num[n][n]的二維數組,但是了可以用vector#include<cstdio>#include<iostream>#include<cstring>#include<vector>#include<algorithm>#define MAXN 50010using namespace
Time of Update: 2018-12-05
今天粗略學習了擴充歐幾裡德演算法。 設a,b,c為任意整數,g=gcd(a,b),方程 ax+by=g的一組解是(x1,y1),則當c是g的倍數時,ax+by=c的一組解是(x1*c/g,y1*c/g);當c不是g的倍數時無整數解。UVA 10104:he ProblemFrom Euclid it is known that for any positive integers A and B there exist such integers X and Y thatAX+BY=D,
Time of Update: 2018-12-05
題目連結線段樹解法#include <stdio.h>#include <algorithm>using namespace std;const int maxn = 100010;struct node{ int l, r, mid, minn;}tree[maxn<<2];int a[maxn];void build(int l, int r, int o){ tree[o].l = l; tree[o].r = r; int m
Time of Update: 2018-12-05
題目連結 WA了很多次,原因在於一個細小的錯誤,#include<cstdio>using namespace std;int f[1000001];int main(){ int a,b,n,i,time; while(scanf("%d%d%d",&a,&b,&n)&&(a||b||n)) { f[1]=1;
Time of Update: 2018-12-05
S-Trees A Strange Tree(S-tree) over the variable set is a binary treerepresenting a Boolean function . Each path of the S-tree begins at the rootnode and consists of n+1 nodes. Each of the S-tree's nodes has a depth, which is the amount
Time of Update: 2018-12-05
Floyd 演算法 就輸入麻煩點#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#define INF 100using namespace std;int a[21][21];int main(){ int n, ca = 1; while(scanf("%d", &n) != EOF) { for(int
Time of Update: 2018-12-05
題目連結DescriptionAstronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star.