hdu 1232——暢通工程 (無最佳化)

 並查集這道題最佳化效果不明顯 #include<iostream>#include<cstdio>#include<cstring>using namespace std;int father[1005];int getfather(int i){while(father[i]!=-1){i=father[i];}return i;}void Union(int x,int y){int fx=getfather(x);int fy=getfather(y)

菜鳥初步最佳化之 最大欄位和

問題:給定n個整數(可能但不全為負)a1,a2,…,an, 求i,j,使ai到aj的和最大。最簡單的是3重迴圈:2重遍曆,1重求和。時間複雜度:O(n3)int MaxSum(int n,int a[],int &besti,int &bestj){ int i,j,sum=0; for(i=1;i<=n;i++) for(j=1;j<=n;j++) {int thissum=0;for(int

hdu 2544——最短路 (spfa)

Problem Description在每年的校賽裡,所有進入決賽的同學都會獲得一件很漂亮的t-shirt。但是每當我們的工作人員把上百件的衣服從商店運回到賽場的時候,卻是非常累的!所以現在他們想要尋找最短的從商店到賽場的路線,你可以協助他們嗎? Input輸入包括多組資料。每組資料第一行是兩個整數N、M(N<=100,M<=10000),N表示成都的大街上有幾個路口,標號為1的路口是商店所在地,標號為N的路口是賽場所在地,M則表示在成都有幾條路。N=M=0表示輸入結束。接下來M行,

hdu 4556 Stern-Brocot

題目Stern-Brocot樹,其建置規則如下:  從第1行到第n行,每行相鄰兩數a/b和c/d,產生中間數(a+c)/(b+d),置於下一行中。將一行的分數(包括0/1,1/0),進行約分簡化,則每一行(包括0/1,1/0,1/1),不會出現兩個相同的分數。若分子或者分母大於n,則去掉該分數,將剩下的分數,從小到大排序,得到數列F。  現在請您編程計算第n行的數列F的個數。/*哥的智商是得有多拙計哥是第一個發表這題解的。。。*/#include<cstdio> #define

hdu 1003 之不斷進步

注意測試資料的多樣性,代碼很活的,代碼風格不太漂亮,待進步。#include<stdio.h>int a[1000001];int main(){ int i,T,n;int best_i,best_j;int

並查集初步探索之1232

最簡單最經典的並查集,精華還沒有理解。#include<stdio.h>int bin[9999];int find(int x){ int r=x; while( bin[r]!=r) r=bin[r]; return r;}void merge(int x,int y){ int fx,fy; fx=find(x); fy=find(y); if(fx!=fy) bin[fx]=fy;}int main(){

背包初步探索之01背包 hdu 2602

#include<stdio.h>int f[2099][2099];int w[2099];int c[2099];int max(int a,int b){ if(a>b) return a; else return b;}int main(){ int T; int i,j; int n,v; scanf("%d",&T); while(T--) {

動態規劃探索之 hdu 2084

#include<stdio.h>#include<string.h>int max(int a,int b){if(a>b)return a;else return b;}int main(){int T,t;int i,j;int f[500][500];memset(f,0,sizeof(f));scanf("%d",&T);while(T--){scanf("%d",&t);for(i=1;i<=t;i++)for(j=1;j<=

背包探索之完全背包

01背包最佳化為一維數組十分靈活。#include<stdio.h>#define NUM 999999int f[99005];int value[2005];int weight[2005];int min(int a,int b){if(a<b)return a;else return b;}int main(){int T,E,F;int i,j,v,n;scanf("%d",&T);while(T--){scanf("%d%d",&E,&F);

hdu 1035——Robot Motion

寬搜#include<cstdio>#include<iostream>#include<cstring>#include<queue>using namespace std;struct Node{int x;int y;};int n,m,sx,sy;char map[20][20];int vis[20][20];int step[20][20];void bfs(){Node start,temp1,temp2;queue<Node&

hdu 1258_Sum It Up hdu

深搜#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int t,n,num[105];int ans[105],flag;void dfs(int x,int k,int sum){int i,j;int last=-1;if(sum>t)return

背包探索之多重背包

#include<stdio.h>#include<string.h>int max(int a,int b){if(a>b)return a;elsereturn b;}int main(){int f[1005];int num[1005];int c[1005];int w[1005];int i,j,k,v,m;int T;scanf("%d",&T);while(T--){scanf("%d%d",&v,&m);memset(f,0

hdu 2717——Catch That Cow

寬搜裸題#include<cstdio>#include<iostream>#include<cstring>#include<queue>using namespace std;queue<int>q;int num[100005];int vis[100005];int x,n;void bfs(int cnt){int temp;while(!q.empty())q.pop();vis[x]=1;q.push(x);memset(

hdu 2209——翻紙牌遊戲

http://www.cnblogs.com/yangcl/archive/2012/01/14/2322433.html#include<cstdio>#include<iostream>#include<cstring>#include<queue>using namespace std;int n,ans;int vis[1<<20+1],dis[1<<20+1];int bfs(int

hdu 1455 ——sticks

深搜——剪枝#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;bool cmp(int a,int b){return a>b;}int num[1000],vis[1000];int n,Sum;int s,K;int flag;//木棍序號 已完成邊數 當前木棍長度 void dfs(int x,int

hdu 1495——非常可樂

記憶化搜尋+寬搜#include<cstdio>#include<iostream>#include<cstring>#include<queue>using namespace std;struct Node{int a,b,c;int step;};int a,b,c;int dp[105][105][105];int flag;int min(int a,int b){return a<b?a:b;}bool Judge(Node

字典樹模型

 統計難題 Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131070/65535K (Java/Other)Total Submission(s) : 52   Accepted Submission(s) : 29Problem

hdu 1166——敵兵布陣 (線段樹)

基礎線段樹#include<cstdio>#include<iostream>using namespace std;struct Node{int l,r;int sum;int Mid(){return (l+r)/2;}}tree[50010*4];void build(int rt,int left,int right){tree[rt].l=left;tree[rt].r=right;if(left!=right){int mid=tree[rt].Mid();

hdu 1532——Drainage Ditches

Dinic演算法 數組版#include<cstdio>#include<iostream>#include<cstring>#include<queue>using namespace std;#define INF 100001int G[205][205],dis[205];int cur[205];int n,m;int Min(int a,int b){ if(a<b) return a; return

HDU 1198——Farm Irrigation

並查集  先用一個數組a來儲存A-K方塊上下左右是否有河道。然後使用並查集,最後判斷有多少個不同的集合。#include<cstdio>#include<iostream>#include<cstring>using namespace std;#define N 55#define M 55int a[11][4]={ 1,0,0,1, 1,1,0,0,0,0,1,1,0,1,1,0,1,0,1,0,0,1,0,1,1,1,0,1,1,0,1,1,0,1,

總頁數: 61357 1 .... 17435 17436 17437 17438 17439 .... 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.