Time of Update: 2018-12-03
隨著海量資料處理的需求增加,並行計算越來越發揮它巨大的作用。通過採用多線程(多進程)的模式對同一任務進行平行處理,可以大大節省處理時間,提高處理效率。並行演算法可以通過資料劃分,得到相應的任務即,然後映射到多個進程。接下來讓我們一窺究竟。 劃分資料 我們知道演算法就是作用於輸入資料,得出一組輸出資料。那麼進行並行計算的一種模式就是對資料進行劃分,包括:劃分輸入資料、劃分輸出資料、劃分中間資料。1)
Time of Update: 2018-12-03
Time of Update: 2018-12-03
轉自:zhanglei8893的專欄4-7 Monge矩陣 一個m x n的實數矩陣A,如果對所有i,j,k和l,1≤ i<k ≤ m和1≤ j<l ≤ n,有 A[i,j]+A[k,l] ≤ A[i,l]+A[k,j]
Time of Update: 2018-12-03
有點煩的題,思路,怎麼說呢,好似不是難,就是那個記錄路徑煩,以前也做過,不過應該大有不同吧這代碼很亂,現在我自己也不願去分析了,其實我應該再寫義多一個結構體去,記錄每步情況,把初始結點情況與其分開,以免過程中改變了初始的情況,而這裡是明顯不應改變的 有一點值得注意的就是,<的重載,其實自對優先順序隊列不熟,所以一開始重載錯了,如沒const和形參用的引用之類的,以後還是先自己寫比較函吧等到偶看了stl再搞起哈#include<iostream>#include&
Time of Update: 2018-12-03
//樹狀數組版#include<stdio.h>#include<string.h>#define N 5005int tree[N];int arr[N];int lowbit(int x){return x&(x^(x-1));}int get_sum(int k){int sum = 0;while(k >= 1){ sum += tree[k]; k -= lowbit(k);}return sum;}void change(int
Time of Update: 2018-12-03
第一次在pku做題,囧死了,這麼一道題調了我N久不過聽說用RMQ-ST演算法更高效,我用線段樹做居然是4047ms有點讓我驚訝,居然可以慢成這樣~~~~~~~~~ #include<stdio.h>#define N 50005struct node{ int l; int r; int min; int max;};node tree[3*N];int arr[N];void buid_tree(int k,int left,int right){int
Time of Update: 2018-12-03
#include<stdio.h>#include<string.h>int arr[50005];int c[50005];int n;int lowbit(int x){x = x & (x ^ (x-1));return x;}void change(int x,int y){while(x <= n){c[x] += y;x += lowbit(x);}}int get_sum(int x){int sum = 0;while(x >= 1){
Time of Update: 2018-12-03
一開始直接上,一個個地修改,然後果斷逾時了,百思不得其解唯有百度,goole看了別人的部落格,雖然現在代碼寫出來了,也明白了演算法,但對於演算法的分析太弱了依然不是很明白為什麼這樣比直接上快這麼多,突然讓我意識到,演算法分析非常重要具有好的演算法分析能力才更有可能設計出更好的演算法,以後這方面得多多加強!!!逾時代碼:#include<stdio.h>#define N 100005struct node{ int l; int r; int sum;};node
Time of Update: 2018-12-03
/*樹狀數組版*/#include<stdio.h>#include<string.h>#define L 32005#define N 15005int tree[L];int count[N];int n;int lowbit(int x){return x & (x ^ (x-1));}int get_sum(int k){int sum = 0;while(k >=1){ sum += tree[k]; k -=
Time of Update: 2018-12-03
第一道離散化是題目,不過這離散也太容易了,不用考慮衝突問題,不用記錄其它距離之類的資料,不過這道題有個囧地方(至少囧到我了),就是樹的數組開3*N不夠,因為我以前都是開3*N,沒出現過問題,這題把寫完後WA了,真有點無語,因為就覺得思路是沒問題的,後來百度下,發現別人都開4*N的,後來想了想,上思修時在紙上畫了差不多一節課,發現根本原因:總的來說對於線段樹最壞開到4*N就定沒問題因為它的結構是一個完全二叉樹,當(N-1)是2的n次方是就是情況最差的時候,這時必須開4*N才可以,不然下標一寫會越界
Time of Update: 2018-12-03
先不說,因為還不是很懂的說~~~~~~#include<iostream>#include<cstdlib>#define N 105using namespace std;struct elem{double x;double s;double t;bool flag;};struct node{int l;int r;int cover;double m;};elem cor[2*N];node tree[8*N];double index[2*N];int len;
Time of Update: 2018-12-03
/*三維樹狀數組*/#include<stdio.h>#include<string.h>#define N 105int tree[N][N][N];int n;int lowbit(int x){return x&(-x);}void tree_change(int x,int y,int z){int flagy,flagz;while(x <= n){flagy = y;while(flagy <= n){flagz = z; while(
Time of Update: 2018-12-03
WA了幾次,都是一些小問題,不夠細心,總是這樣這幾天一直就在搞線段樹和樹狀數組,也不知道怎麼說好,對於樹狀數組更新區間問題依依然雲裡霧裡的說,我想是我還是沒有理解好樹狀數組那兩個函數的本質在網上看到一個博文說其實它們本質是一樣的,可以交換使用,不過自己還沒有測試過#include<stdio.h>#include<string.h>#define EXCHANGE(a,b) (a) ^= (b);(b) ^= (a);(a) ^= (b)#define N
Time of Update: 2018-12-03
只能說與pku1151相似,別的還沒有發言權哎~~~~~~~~~~願自己一路走好!!!!! 代碼: #include<iostream>#include<cstdlib>#include<cmath>#define N 5005using namespace std;struct elem{double x;double ly;double ry;bool flag;};struct node{int l;int r;int lc,rc;int
Time of Update: 2018-12-03
節點儲存區間的最大值,父結點儲存左右結點中大的那個,建樹時比較下就是了#include<stdio.h>#define N 200005struct node { int l; int r; int max;};node tree[3*N];int arr[N];void buid_tree(int k,int left,int right){int mid;int L,R;tree[k].l = left; tree[k].r = right;if(right -
Time of Update: 2018-12-03
雖然是過,其實我也沒想會過,這樣做竟不逾時,有點厲害不過也有點慢了,回來再做過我用了lazy思想,由於每次都要tree_search使得其很慢,網上有些代碼是增加記錄域ylenonce,ylenmore分別是記錄覆蓋一次的長度,覆蓋二次以上的長度這樣就不要tree_searh了,快了不知多少~~~ My Code:#include<iostream>#include<cmath>#include<cstdlib>#define N 1005using
Time of Update: 2018-12-03
#include<stdio.h>#define N 5005struct node{ int l;int r;int sum;};int arr[N];node tree[3*N];void buid_tree(int k,int left,int right){int mid;int L,R;tree[k].l = left; tree[k].r = right;if(right-left == 1){tree[k].sum = 0;return ;}L = 2*k; R
Time of Update: 2018-12-03
不知值不值得開心,這題我是沒有百度,google的說,自己的方法過的感覺就是不一樣前天做了pku的346覺得思路用在這題也行,結果還真的,嘻嘻~~#include<stdio.h>#define N 100005struct node{ int l; int r; int sum; int add; node *after;};node tree[3*N];node *(p1[N]);//指標數組,指向,各個葉子結點void buid_tree(int
Time of Update: 2018-12-03
先上:再上代碼:public class ImageToast {/** * @author spare_H * @param msg 顯示的內容 * @param resId 顯示的圖片資源的id * @param which 顯示方式1.添加一個TextView和一個ImageView2.只添加一個TextView */public static void ShowToastwithImage(Context context, String msg,int resId,
Time of Update: 2018-12-03
#include<stdio.h>#include<string.h>#define L 32000#define N 15000struct node{ int l; int r; int sum;};node tree[3*L];int count[N] = {0};int n;void buid_tree(int k,int left,int right){int mid;tree[k].l = left; tree[k].r =