Time of Update: 2018-12-03
http://acm.nyist.net/JudgeOnline/problem.php?pid=8注意,用sort排序的時候,傳的是(開始位置的指標,接受比較的指標);然後就是在結構體重,重載操作符,注意在結構體中,如果想按一定的規律排序是必須重載操作符的,包括< ==.重載操作符下面是用qsort寫的.代碼如下:#include <stdio.h>#include <algorithm>#include <stdlib.h>#include <
Time of Update: 2018-12-03
RMQ(space table演算法)/*RMQ(Range Minimum/Maximum Query)問題: RMQ問題是求給定區間中的最值問題。當然,最簡單的演算法是O(n)的,但是對於查詢次數很多(設定多大100萬次),O(n)的演算法效率不夠。可以用線段樹將演算法最佳化到O(logn)(線上段樹中儲存線段的最值)。不過,Sparse_Table演算法才是最好的:它可以在O(nlogn)的預先處理以後實現O(1)的查詢效率。下面把Sparse
Time of Update: 2018-12-03
/* hdu 1272 簡單並查集 只要查有沒有迴路就夠了 只要有共同根節點 就必然有迴路*/#include <cstdio>#include <algorithm>#define maxn 100005using namespace std;int father[maxn];int vis[maxn];//int map[maxn][maxn];int find(int x){ if(father[x]!=x) return
Time of Update: 2018-12-03
原來就是初始化的時候要把所有的d都初始化為1;因為每一個點的,初始化結果就是1;開始的時候沒有意識到,,,#include <stdio.h>#include <string.h>#include <iostream>#include <string>#include <algorithm>#define max(a, b) (a) > (b) ? (a) : (b)using namespace std;const int
Time of Update: 2018-12-03
1、系統應具備的功能:(1)進貨員對商品基本資料進行輸入、刪除、修改和查詢(2)銷售人員對商品的基本資料進行查詢和統計(3)並可以對庫存資訊進行查詢和修改 (4)顧客購買商品2、要求: (1)介面劃分清晰,功能全面(2)操作方便。(3)資料結構選擇合理,演算法正確。 儲存結構 1、 使用者儲存採用sqlite資料庫,提高資料庫的安全性、便利性。2、 對商品的一系列屬性用結構體表示,對商品名建立雜湊表,借用STL裡的MAP類。3、
Time of Update: 2018-12-03
希爾排序還是不錯的,時間複雜度在O(n^1.3)這是我自己寫出來的代碼,我什麼也沒看別人的代碼就是根據自己的理解自己敲出來的,大家看看:#include <stdio.h>#include <string.h>#include <math.h>#include <iostream>#include <algorithm>#include <string>using namespace std;int
Time of Update: 2018-12-03
To the MaxTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 36015 Accepted: 18897DescriptionGiven a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1*1 or greater located within
Time of Update: 2018-12-03
描述在國際象棋棋盤上放置八個皇后,要求每兩個皇后之間不能直接吃掉對方。輸入無輸入。輸出按給定順序和格式輸出所有八皇后問題的解(見Sample Output)。範例輸入範例輸出No. 11 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 No. 21 0 0 0 0 0 0 0 0 0 0 0 0
Time of Update: 2018-12-03
二分法作為分治中最常見的方法,適用於單調函數,逼近求解某點的值。但當函數是凸性函數時,二分法就無法適用,這時三分法就可以“大顯身手”~~ ,類似二分的定義Left和Right,mid = (Left + Right) / 2,midmid = (mid + Right) / 2; 如果mid靠近極值點,則Right = midmid;否則(即midmid靠近極值點),則Left = mid;程式模版如下:double Calc(Type a){ /* 根據題目的意思計算 */}
Time of Update: 2018-12-03
/* poj 3041 匈牙利演算法 題目大意:每次開槍能清除一行或者一列,問最少開多少槍能清理完 分析:將每一行和每一列看做兩個點 而小行星看做連結兩點的線 舉個例子看:第i行(列)看做點行i,點列i, 假設第一行上所有格子都有小行星,那麼也只能匹配一個列i,也就是一槍就掃除了該行 假設第一列上所有格子都有小行星,那麼也只能匹配一個行i,也就是在該列上只有一槍
Time of Update: 2018-12-03
/* poj 1276 多重背包 題目的意思大概是能給定一個需要籌集到的貨幣m, 給定擁有的幾個貨幣數量n[i]和價值v[i],問你最多能籌到多少錢 是一個多重背包問題 dp[j]代表容量為j的背包最多能裝多少價值的物品 一般遇到多重背包的解法是將其轉化成完全背包和01背包去解 代碼如下:*/#include <cstdio>#include <algorithm>using namespace std;#define
Time of Update: 2018-12-03
/* poj 3020 最小路徑覆蓋 題目一開始沒看懂 囧 參考了網上的代碼,這是個最小路徑覆蓋的問題 o代表不需要覆蓋天線的地方 *代表需要覆蓋天線的地方 一根天線可以惠及兩個相鄰的*點,問最少需要多少天線才能把所有*點覆蓋完 無向二分圖的最小路徑覆蓋=點數-最大匹配/2 建模過程:將每個*點看做點,進行拆點*/#include <cstdio>#include <cstring>using namespace std;
Time of Update: 2018-12-03
/* POJ 1836 dp 依然是最長上升和下降子序列的問題 題目有個陷阱,那就是像1 2 3 4 4 3 2 1這樣的資料是不需要任何士兵出列的 所以只要分別求出dp[i](表示以i為結束的上升子序列) 和dp2[i](以i為起點的下降子序列) 枚舉中點 找出他們相加的最大值*/#include <cstdio>#include <algorithm>#include <cstring>using
Time of Update: 2018-12-03
暴力法和線段樹都能解題 暴力法109ms,線段樹62ms/* hdu 1394 逆序對 線段樹做法 逆序對:即i>j ,a[i]<a[j]的序列 比如 3 2 1 4中, {3,2},{3,1}{2,1}是逆序對 為什麼想到線段樹做法? 因為這是一個區間求和問題,即求a[i]+1~n-1的總數 這樣自然就能用線段樹快速解題 */#include <cstdio>#define maxn
Time of Update: 2018-12-03
1、設計演算法,對帶頭結點的單鏈表實現就地逆置。並給出單鏈表的儲存結構(資料類型)的定義。#include <iostream>#include <cstdlib>#include <cstdio>#include <ctime>using namespace std;typedef char ElemType;typedef struct Node{ElemType data;struct Node *next;}Node, *LinkList;
Time of Update: 2018-12-03
漫步校園Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2077 Accepted Submission(s): 597Problem DescriptionLL最近沉迷於AC不能自拔,每天寢室、機房兩點一線。由於長時間坐在電腦邊,缺乏運動。他決定充分利用每次從寢室到機房的時間,在校園裡散散步。整個HDU校園呈方形布局,可劃分為n*
Time of Update: 2018-12-03
/* hdu 1556 線段樹 要成段更新資料 否則會造成逾時!~~~~*/#include <cstdio>#include <cstring>using namespace std;#define maxn 100005int ans[maxn];int k;struct Node{ int l,r,v;}node[maxn*4];int n;void build(int i,int ls,int rs){
Time of Update: 2018-12-03
/* hdu 1086 求線段交點個數 */#include <cstdio>#include <algorithm>using namespace std;#define maxn 105int n;struct point{ double x, y;}s[maxn],e[maxn];//叉積double multi(point p0, point p1, point p2){ return ( p1.x - p0.x )*( p2.y - p0
Time of Update: 2018-12-03
/* hdu 2063 最大二分匹配 匈牙利演算法 我做的第一道二分匹配題目~*/#include <cstdio>#include <cstring>using namespace std;#define maxn 505bool used[maxn];bool map[maxn][maxn];int match[maxn];int m,n,k;bool find(int x){ for(int i = 1; i &
Time of Update: 2018-12-03
此文轉自 http://t.cn/zjyTuab如果問題中各資料的範圍明確,那麼無窮大的設定不是問題,在不明確的情況下,很多程式員都取0x7fffffff作為無窮大,因為這是32-bit int的最大值。如果這個無窮大隻用於一般的比較(比如求最小值時min變數的初值),那麼0x7fffffff確實是一個完美的選擇,但是在更多的情況下,0x7fffffff並不是一個好的選擇。很多時候我們並不只是單純拿無窮大來作比較,而是會運算後再做比較,例如在大部分最短路徑演算法中都會使用的鬆弛操作:if