鏈表模版

簡單的鏈表模版#include<cstdio>#include<iostream>#include<cstring>using namespace std;struct edge{int u,v,c;int next;}e[10000];int cnt;int head[1000];void init(){cnt=0;memset(head,-1,sizeof(head));}void add(int u,int v,int

最小產生樹 prim

#include <iostream>#include <cstdio>#include <cstring>const int INF=1000000000;const int maxn=510;using namespace std;int map[maxn][maxn],dis[maxn],visited[maxn];int main(){int

RMQ演算法模版

RMQ演算法用於尋找區間內最小的值,他的預先處理時間為O(nlogn),但是查詢O(1)。#include<iostream>using namespace std;int d[104][104];int a[104];int n;int min(int a,int b){ return a<b?a:b;}void RMQ_init(){ int i,j; for(i=1;i<=n;i++) d[i][0]=a[i]; for(j=1

hdu 1175——連連看

深搜+剪枝#include<iostream>#include<cstdio>using namespace std;int map[1010][1010];int dir[4][2]={-1,0,1,0,0,-1,0,1};// 上下 左右 int flag;int n,m;int x1,x2,y1,y2; void dfs(int x,int y,int k,int d){int i,j;int temp;if(flag)return ;if(x==x2&&

POJ3171 Cleaning Shifts 資料結構

http://poj.org/problem?id=3171這是一道資料結構題,題目大意為 :   FJ要打掃區間[M..E],有N 頭奶牛,他們打掃區間 [T1,T2]的費用S。問最少要花費多少錢才能打掃完區間[M..E],如果 無法打掃完,就輸出-1。    這是一道比較簡單的資料結構題,但稍微用到了dp的思想。   

HDU 2648——shopping

雜湊函數#include<vector>#include<iostream>#include<cstring>using namespace std;#define N 5000struct note{char name[35];int price;};note temp;int hash(char *ch)//hash函數,依照我的理解是產生一個離散的數字 {int key=0;int

hdu 1181——變形課

做法一:最短路 dij#include<iostream>#include<cstring>#include<cstdio>using namespace std;#define INF 1000001int map[26][26];int dis[26];int vis[26];int s='b'-'a',e='m'-'a';void makeset(){int i,j;for(i=0;i<26;i++)for(j=0;j<26;j++)map[

[毅周總結]資料結構(2)

   由於第一周上課聽的的實在太水了,課的難度比我想象的難得多,結果這兩周都在補課呢.............題就做的少了點,主要還是線段樹,寫了一道樹鏈剖分,但掛了,智商拙計啊。   還是說說這周做的印象比較深的題吧:     NO.1  POJ 2528 mayor‘s poster    說實話這題不難,自己寫的也挺快。但確實,沒有動腦子。我是線上段上加一個標誌域c,由c來判斷該地區是否有多種顏色,或者是否全由一種顏色覆蓋;在最後覆蓋完成之後,再去查詢,這些線段樹上有多少種顏色。 

迷宮的最短路徑

Problem

Bone Collector 2602 0-1背包問題

簡單的 0-1背包問題#include<iostream>#include<cstdio>#include<cstring>using namespace std;int Max(int a,int b){if(a>b)return a;return b;}int main(){int t,n,v,i,j,value[1003],volume[1003];int dp[1003];scanf("%d",&t);while(t--){scanf("

並查集—-poj解題

文章目錄 1789---Truck Historypoj2377---Bad Cowtractors 1182---食物鏈f[n]和delt[n]分別儲存集合關係和父子關係,f[i]表示i的父親是f[i],delt[i]表示i與f[i]的關係,如果delt[i]=0,表示i與f[i]同類;如果delt[i]=1,表示i吃f[i];如果delt[i]=2,表示f[i]吃i;#include

hdu 1016 Prime Ring Problem

/* hdu 1016 搜尋*/#include <iostream>#include <cstdio>#include <cstring>using namespace std;int n,t;int prime[45],visit[25],ans[25];void sushu() //打表求出素數,篩選法{ //因為最大輸入數是19,所以求出40以內的素數即可 for(int i=1;i&

POJ2777—線段樹

成段更新,在節點處lazy標記有很大協助,有了lazy標記每次更新時就不用更新到底了。#include <iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define N 100005int n,m,t,sum;char str[2];bool color[33];struct TNode{ int l,r,color;}

HDU-4552 怪盜基德的挑戰書

KMP演算法有KMP的想法在,預先處理是一樣的。這是白書上的KMP演算法的寫法。#include<cstdio>#include<iostream>#include<cstring>using namespace std;void getFail(char* P,int* f){int m=strlen(P);f[0]=0;f[1]=0;for(int i=1;i<m;i++){int j=f[i];while(j&&P[i]!=P[j]

hdu 4628 ——Pieces

記憶化搜尋+狀態壓縮一直逾時,看了標程後改了一個地方。自己還是太菜啊#include<iostream>#include<cstdio>#include<cstring>using namespace std;#define maxn 16#define INF 1<<30char a[maxn+1];int pali[1<<maxn];//是否是迴文 int dp[1<<maxn];//需要的step int n;int

POJ3667—線段樹

//對連續空間的插入和刪除//snum---表示此節點下空間個數,ls---表示此節點從左開始的空間個數,rs---表示此節點從右開始空間個數//在查詢時,按左節點、左節點---右節點、右節點的次序查詢//在每次查詢時都要向下更新;在查詢成功時,要向上更新#include <iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace

Hdu 1754——I Hate It

線段樹單點更新#include<cstdio>#include<iostream>using namespace std;struct Node{int left;int right;int max;}node[200000*4];int Max(int a,int b){return a>b?a:b;}void TreeMake(int l,int r,int

poj2482—線段樹

//和求矩形覆蓋面積相似//以每個星星為左下角建立一個W*H的矩形,把矩形的左右邊離散出來,左邊的線段權值為val,右邊的線段權值為-val//排序後,從左至右掃描//注意在向上更新時,節點root的最大值應是2*root與2*root+1值的最大者//向下更新//注意建立矩形時,邊可以超出int範圍//排序時,x相等則按val從大到小排#include

poj3468—線段樹

//線段樹成段更新//和其他題相似,注意在更新時值可以超出int範圍,在乘的時候,應乘1ll強制類型轉換#include <iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define N 100005typedef __int64 i64;int n,m,t;i64 sum;int ans[N];char

[毅周總結]資料結構(1)

    這周重新開始學習演算法,先從資料結構開始。這個星期學的主要還是基礎的資料結構,做的題主要集中線上段樹和樹狀數組這個方面,但也看了其他的一些進階資料結構的演算法,希望下周能夠做些題。   講講這周給我印象比較深的題:   NO.1  poj 2155 Matrix  

總頁數: 61357 1 .... 17432 17433 17434 17435 17436 .... 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.