hdu 1217——Arbitrage

弗洛伊德演算法,就是下面三重迴圈。for(i=0;i<n;i++)for(j=0;j<n;j++)for(k=0;k<n;k++)if(map[j][i]*map[i][k]>map[j][k])map[j][k]=map[j][i]*map[i][k];代碼#include<cstdio>#include<cstring>#include<iostream>using namespace std;char

HDU 1599 find—— the mincost route

題意可以理解為求有至少帶3個節點的環的最小值。#include<cstdio>#include<iostream>#include<cstring>using namespace std;#define INF 100001int map[102][102],dis[102][102],num[102];int min(int a,int b){return a<b?a:b;}int main(){int n,m,s,e,cost,ans;int

並查集模版——實現了路徑壓

今天花了時間在網上學了並查集。先上例題,解析在注釋裡。題目: 親戚(Relations)或許你並不知道,你的某個朋友是你的親戚。他可能是你的曾祖父的外公的女婿的外甥的表姐的孫子。如果能得到完整的家譜,判斷兩個人是否親戚應該是可行的,但如果兩個人的最近公用祖先與他們相隔好幾代,使得家譜十分龐大,那麼檢驗親戚關係實非人力所能及.在這種情況下,最好的幫手就是電腦。</為了將問題簡化,你將得到一些親戚關係的資訊,如同Marry和Tom是親戚,Tom和B

HDU 1224——Free DIY Tour

 弗洛伊德演算法題意為從城市1到城市n+1,求經過的城市的有趣值之和最高的路線。並且旅遊路線只能是序號小的城市到序號大的城市。#include<iostream>#include<cstdio>using namespace std;#define maxn 105#define INF -100001int map[maxn][maxn],path[maxn][maxn],val[maxn];//path代表從i到j這條路線中,i之後的節點。int

poj 3468——A Simple Problem with Integers

線段樹 #include<iostream>#include<cstdio>using namespace std;#define maxn 100005#define LL __int64#define ls (rt<<1)#define rs (rt<<1|1)#define mid ((t[rt].l+t[rt].r)>>1)LL n,m;struct tree{LL l,r;LL sum;LL lazy;}t[maxn<&

HDU1598 ——find the most comfortable road(並查集)

將邊按速度進行從小達到的排序,設i是最大速度的邊,通過枚舉比i小的邊 for(j=i;j>=0;j--)  如果找到起點和終點在同一個集合裡,更新min。測試資料較小,枚舉不會逾時。#include<iostream>#include<algorithm>#include<cstdio>using namespace std;#define maxn 400#define INF 100000001int father[maxn],rank[maxn],

HDU 1235 最大連續子序列

亂搞#include<cstdio>#include<iostream>using namespace std;int main(){int n;int num[10005];int flag;int i;while(cin>>n&&n){flag=1;for(i=0;i<n;i++){scanf("%d",&num[i]);if(num[i]>=0){flag=0;}}if(flag){printf("0 %d %d\n"

HDU 2824——The Euler function

篩法求歐拉函數求歐拉函數的公式:φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/pn),其中p1, p2……pn為x的所有質因數,x是不為0的整數。φ(1)=1(唯一和1互質的數就是1本身)。 (注意:每種質因數只一個。比如12=2*2*3 那麼φ(12)=12*(1-1/2)*(1-1/3)=4)這題資料量比較大用普通的歐拉函數肯定逾時。這裡運用類似素數篩選法的

KMP演算法模版

網上KMP講的很清楚好http://blog.csdn.net/ts173383201/article/details/7850120我按著自己的理解寫了個模版。主要參考白書。理解很淺顯,先放著。#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(

HDU 1272——小希的迷宮

並查集。該題只要成立2個條件,則輸出Yes(輸出請注意大小寫)。第一個條件是該圖中沒有環。第二個條件是並查集只有一個集合。構成環的條件是2個點已經是在相同的集合裡,但是讓他們再並成一個集合,這樣就構成了環。小心測試資料 0 0 Yes 1 1 0 0 Yes#include<cstdio>#include<iostream>using namespace std;#define maxn 100005int father[maxn],rank[maxn],n=maxn-2

HDU 1596——find the safest road

最小產生樹dij演算法就可解決。#include<cstdio>#include<cstring>#include<iostream>using namespace std;#define maxn 1005double map[maxn][maxn],dis[maxn];bool que[maxn];int main(){int n,i,j;while(scanf("%d",&n)!=EOF){for(i=1;i<=n;i++)for(j=1;

HDU 2833——wukong

dijskra演算法+搜尋首先分別求出悟空和唐僧各自的最短路徑,然後記憶化搜尋。#include<cstring>#include<cstdio>#include<iostream>using namespace std;#define maxn 302#define INF 10001int map[maxn][maxn],dis1[maxn],dis2[maxn];int dp[maxn][maxn];void dij1(int s,int e,int

hdu 4614——Vases and Flowers

線段樹線段樹太渣了,看別人代碼惡補下。http://www.cnblogs.com/aukle/archive/2013/07/26/3217639.html#include<iostream>#include<cstdio>using namespace std;#define maxn 50010#define ls (rt<<1)#define rs (rt<<1|1)#define mid

HDU 4135——Co-prime

容斥原理題意為輸入a,b,n。找到區間[a,b]間與n互質的數的數量.首先我們將n拆分成質因數.利用容斥原理,答案就是b-a+1減去有奇數個質因子的數,加上有偶數個質因子的數.#include<cstdio>#include<iostream>#include<cmath>using namespace std;__int64 rec[6000000],k,ans,a,b,n,N;__int64 GCD(__int64 a,__int64 b){__int64

最短路徑問題 hdu 3790

水題,不多說。#include<iostream>#include<cstdio>#include<cstring>#define INF 1000001using namespace std;int map[1002][1002][2],dis[1002],cost[1002];int que[1002];int main(){int n,m,i,j,s,e,min,k;int

二逼 普通 文藝的素數篩選法

二逼的素數篩選法2b的篩選法,不多說。const int N=1000000;bool pr[N];int p[N],lp;bool isprime(int x){ for(int i=2;i*i<=x;i++) if(x%i==0) return 0; return 1;}void initp(){ for(int i=2;i<N;i++) if(isprime(i)){ pr[i]=1;

HDU 2112——HDU Today

最小路徑的題目,地名的處理是把各個地名標記序號即可。需要注意的是這題是的公交起點站可到終點站,終點站也可到起點站。另外給出兩個相同地點時,輸出是0.#include<iostream>#include<cstdio>#include<cstring>using namespace std;#define INF 1000000int map[160][160],dis[160];bool que[160];char place[160][35];int

poj 3264——Balanced Lineup

線段樹#include<iostream>#include<cstdio>using namespace std;#define maxn 50004#define ls (rt<<1)#define rs (rt<<1|1)#define mid ((t[rt].l+t[rt].r)>>1)struct tree{int l,r;int max,min;}t[maxn<<2];int n,m;void

程式員才看得懂的情書

我能把整個世界都抽象成對象...   但是沒辦法把你變成我的對象...   想讓你成為私人常量,外部函數無法訪問你…   又想讓你變成全域常量,在整個生命週期隨時隨地都可以調用你…   因為世界上沒有這樣的常量...  所以我的無法定義你...   我可以重載甚至覆蓋任何一種方法...   但是我卻不能重載對你的思念...   也許命中註定了 你在我的世界裡永遠的烙上了靜態屬性...      而我不慎調用了愛你這個方法...   當我義無返顧的把自己作為參數傳進這個方法時...  

HUD 1978——How many ways

記憶化搜尋。 假設起點變成(n,m),終點變成(1,1)。dp[i][j]儲存到起點該點的路徑數。賦值dp[n][m]=1.從(1,1)往回搜尋,一旦遇到dp>0.說明已經被搜尋過了,直接返回。#include<cstdio>#include<iostream>#include<cstring>using namespace std;#define maxn 105#define mod 10000int map[maxn][maxn],dp[maxn]

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