POJ 2388 Who’s in the Middle(堆排序)

今天看《演算法導論》學了堆排序,試下改用堆排序來寫複雜度O(nlgn),還能為霍夫曼樹的最佳化作鋪墊//堆排序#include<iostream>using namespace std;int arr[10001],n;inline int left(int i)//返回左兒子的數組下標,要用內聯或宏定義寫{return 2*i;}inline int right(int i)//返回右兒子下標{return 2*i+1;}void max_heapify(int

POJ 3253 Fence Repair(構造Huffman Tree)

//構造Huffman Tree,非葉子節點值總和即為結果,用最小優先隊列維護#include<iostream>#include<queue>using namespace std;priority_queue<int,vector<int>,greater<int> > q;//最小優先隊列,用greater<int>作為比較函數即可,less<int>則為最大優先隊列int

POJ 1338 Ugly Numbers(類比)

//因為沒有理解ugly number的意思WA了2次,還好有Discuss....//ugly_num中每一個數都得基於裡頭有的數去乘2,3,5,//例如14不是ugly_num因為7*2=14,但7不是ugly_num裡面有的#include<iostream>using namespace std;long ugly_num[1501];int pFactor2,pFactor3,pFactor5,n;int main(){pFactor2 = pFactor3 =

POJ 1125 Stockbroker Grapevine(求最短路徑—Floyd演算法)

//Floyd演算法——求最短路徑#include<iostream>using namespace std;const int INF = 200000000;//注意Floyd初始值的INF值不能太大,否則後面加法的時候會溢出,應當估計實際最短路長度上限,並將INF設定為比它大一點點即可int map[101][101],maximum,flag,minimum,n,p,k;int main (){while(cin >> n){if(n ==

Sicily 1156 Binary tree(搜尋)

//簡單的搜尋題#include<iostream>#include<vector>using namespace std;struct Node{char id;int left;int right;bool root;}node[1001];void print(int i)//遞迴列印先序遍曆{if(i == 0)return;cout <<

POJ 2243 ZOJ 1091 UVaOJ 439 Knight moves(BFS廣度優先搜尋)

//典型的BFS(廣度優先搜尋)//馬走日所需最少步數問題#include<iostream>using namespace std;int map[8][8];//記錄步數數組int vis[8][8];//訪問過的記錄數組char a[3],b[3];int x1,y1,x2,y2;void set(int x1,int y1){//剪去不合理範圍if(x1+1 <= 7 && y1+2 <= 7 && !vis[x1+1][y1+2]

POJ 1017 Packets(貪心)

//用貪心演算法,從最大的裝起,//5*5->1*1;//4*4->2*2->1*1;//3*3分3種情況//模4後剩1,剩2,剩3//剩1的最多可再裝5個2×2,再補1×1//剩2的最多可裝4個2×2,再補1×1//剩3的只能裝多1個2×2,再補1×1#include<iostream>using namespace std;int main(){int a[7],n,c; // n為數量,c為容量for(;;){n = 0;c = 36;for(int i =

POJ 1328 Radar Installation(貪心)

//貪心,注意貪心的方式,一開始我用從左往右對每一個點所對應的最右圓心座標,接著逐步右移判斷,看了POJ上的大牛討論,知道這個演算法是錯誤的,於是進行了改正//正確的貪心演算法應當是求出每個點它所滿足的圓心範圍,接著將問題轉化為多區間選點問題。//即在N個閉區間上取盡量少的點,使得每個區間內都至少有一個點(不同區間內含的點可以是同一個)#include<iostream>#include<cmath>using namespace std;struct

POJ 2209 The King(類比)

//水題,注意當指數為2的情況即可#include<iostream>using namespace std;int main(){int n,e,sum = 0,son[101];cin >> n >> e;for(int i = 1;i <= n;++i)cin >> son[i];if(e == 2)for(int i = 1;i <= n;++i)sum += son[i] * son[i];else if(e ==

最後一堂語文課的筆記

能夠被朱崇科老師教大學語文,確實是一件榮幸的事。 一、人生設計1.腳踏實地A做好細節(當你看到別人把細節做好時,其實這隻是表象,其背後是一種強大的對生活的熱忱)B堅韌不拔C言出必行(你可以少說,也可以不說,但是絕對不可以說了不做) 2.一點理想主義A遠期理想B近期目標C非功利性(只有在內心中留著一點非功利的空間,當你遇到挫折時,才可以繼續堅持下去) 3.成仁成義A合法權益(當你面對不公,一定要通過合法手段捍衛自己的權益!)B義字當頭 二、愛情1.有期待 有憧憬2.有準備 要理性3.不極端

POJ 1013 Counterfeit Dollar

DescriptionSally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are true silver dollars; one coin is counterfeit even though its color and size make it indistinguishable from the real silver dollars. The counterfeit

POJ 2000 Gold Coins(類比)

//簡單類比題#include<iostream>#include<cmath>using namespace std;int main(){int day,coin,n;while(cin >> day){if(day == 0)break;coin = 0;n = floor(sqrt((double)day*2) - 0.5);//該天數每天獲得的金幣數for(int i = 1;i <= n;++i)for(int j = 1;j <=

HDU 2050 折線拆分平面

Problem Description我們看到過很多直線分割平面的題目,今天的這個題目稍微有些變化,我們要求的是n條折線分割平面的最大數目。比如,一條折線可以將平面分成兩部分,兩條折線最多可以將平面分成7部分。 Input輸入資料的第一行是一個整數C,表示測試執行個體的個數,然後是C 行資料,每行包含一個整數n(0<n<=10000),表示折線的數量。 Output對於每個測試執行個體,請輸出平面的最大分割數,每個執行個體的輸出佔一行。Sample Input212Sample

POJ 2081 Recaman’s Sequence(類比/暴力)

//純粹暴力AC,必須記住大數組一定要開成全域變數,因為函數裡面的定義的變數都是放在棧堆中,太大會溢出即stack overflow#include<iostream>using namespace std;int arr[500001];bool used[3012500];int main(){int n;arr[0] = 0;memset(used,0,sizeof(used));used[0] = 1;for(int i = 1;i <= 500000;++i){if(

POJ 1042 Gone Fishing(貪心)

還可以用資料結構堆最佳化,還有待學習!//貪進法#include <iostream>using namespace std;struct lake{ int f;//當前魚的數量 int d;//減少量 int t;//步行所花時間}la[26];int fish[26];//記錄目前狀態每個湖所含魚的數量int sum[26];//以不同湖為結束點可以釣到的最大魚數量int

Dynamic Programming(DP)—動態規劃

一、概念及意義       動態規劃(dynamic programming)是運籌學的一個分支,是求解決策過程(decision process)最佳化的數學方法。20世紀50年代初美國數學家R.E.Bellman等人在研究多階段決策過程(multistep decision process)的最佳化問題時,提出了著名的最佳化原理(principle of

POJ 1083 Moving Tables(類比)

題目陷阱:一、輸入的兩個房間號不一定是從小到大,因此若第一個大於第二個需要SWAP二、2和3,4和5不能同時過,因為佔用了3這個過道,而1和2,3和4就能同時通過 解法:將房間號進行轉化,轉化成可以用200個位置來代表過道。開個數組代表房間,對過道重複的進行標記,數組中最大數則為所求。 #include<iostream>using namespace std;intmain(){introom[201],n,max,r1,r2,test;const inttime =

某公司對IT程式員的要求

聽某個公司的以講座名義的大學生招聘宣傳會瞭解到得資訊,記錄下  職位要求: 1.電腦(或相關專業)本科(或以上)畢業 2.瞭解物件導向軟體設計方法和設計模式 3.熟悉MVC WEB架構等技術 4.熟悉掌握至少下列一下一種資料庫產品:Oracle,MySQL 5.熟悉主要的WEB介面構建技術,HTML/XHTML, JAVASCRIPT, CSS和AJAX技術 6.有強烈的進取精神,能夠在壓力下工作 7.具有較強的學習能力,良好的英語閱讀能力 8.擁有SCJP認證者優先考慮

HDU 1021 Fibonacci Again

Problem DescriptionThere are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).  InputInput consists of a sequence of lines, each containing an integer n. (n < 1,000,000).  OutputPrint the word "yes" if 3

HDU 1061 Rightmost Digit

 Problem DescriptionGiven a positive integer N, you should output the most right digit of N^N.  InputThe input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.Each

總頁數: 61357 1 .... 13017 13018 13019 13020 13021 .... 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.