SPFA水題六枚

2021-06-08 13:34:26 字數 3012 閱讀 1185

hdu 1548

純水,無需建圖,每個點最多只有兩條邊……

const int maxv = 240;

bool inq[maxv];

int n,src,des,a[maxv],dis[maxv],q[maxv];

bool within(int v,int n)

}v=u-a[u];

if(within(v,n)&&dis[v]>dis[u]+1)}}

return dis[des]!=inf?dis[des]:-1;

}int main()

printf("%d\n",spfa(src-1,des-1));

}return 0;

}

hdu 2544

純水不解釋,毫無trick……

const int maxv = 101;

const int maxe = 20002;

struct node

g[maxe];

int _index,pre[maxv],next[maxe];

void clear(void)

void add(int u,int v,int w)

bool inq[maxv];

int dis[maxv],q[maxv];

int spfa(int src,int des)}}

}return dis[des];

}int n,m,u,v,w;

int main()

printf("%d\n",spfa(0,n-1));

}return 0;

}

hdu 3790

二維距離(路程,**),優先判斷路程……

const int maxv = 1200;

const int maxe = 240000;

struct node

g[maxe];

int _index,pre[maxv],next[maxe];

void clear(void)

void add(int u,int v,int w,int c)

bool inq[maxv];

int dis[maxv],pay[maxv],q[maxv];

int spfa(int src,int des)}}

}return dis[des];

}int n,m,u,v,w,c,s,t;

int main()

scanf("%d %d",&s,&t);

spfa(s-1,t-1);

printf("%d %d\n",dis[t-1],pay[t-1]);

}return 0;

}

hdu 2066

加源點匯點直接跑spfa,trick在於點的編號是亂的……

const int maxv = 1200;

const int maxe = maxv*maxv*20;

struct node

g[maxe];

int _index,pre[maxv],next[maxe];

void clear(void)

void add(int u,int v,int w)

bool inq[maxv];

int dis[maxv],q[maxv];

int spfa(int src,int des)}}

}return dis[des];

}int t,s,d,u,v,w;

int main()

for(int i=0;s>i;i++)

for(int i=0;d>i;i++)

printf("%d\n",spfa(0,1));

}return 0;

}

hdu 2112

無向邊,直接對映點的進行編號就好了,注意點標號……

const int maxv = 2400;

const int maxe = 24000;

struct node

g[maxe];

int _index,pre[maxv],next[maxe];

void clear(void)

void add(int u,int v,int w)

bool inq[maxv];

int dis[maxv],q[maxv];

int spfa(int src,int des)}}

}return dis[des]!=inf?dis[des]:-1;

}int n,w,tot;

char u[32],v[32],s[32],t[32];

mapname;

int main()

printf("%d\n",spfa(name[s],name[t]));

}return 0;

}

hdu 1874

無槽點直水……

const int maxv = 240;

const int maxe = 2400;

struct node

g[maxe];

int _index,pre[maxv],next[maxe];

void clear(void)

void add(int u,int v,int w)

bool inq[maxv];

int dis[maxv],q[maxv];

int spfa(int src,int des)}}

}return dis[des]!=inf?dis[des]:-1;

}int n,m,u,v,w,s,t;

int main()

scanf("%d %d",&s,&t);

printf("%d\n",spfa(s,t));

}return 0;

}

Unity C 爆破計畫(六) 列舉和結構體

covers 列舉和結構體 列舉是一種有限集合。生活中的有限集合很多,比如 一周中每天的名稱 只有 7 種 生日對應的星座 只有 12 種 現在好像是 13 種了?這些事物都適合用列舉來描述。寫乙個列舉的例子 using system namespace enums class program 我們...

C 程式語言(六) 列舉型別與結構型別

列舉型別 列舉型別 也稱為列舉 為定義一組可以賦給變數的命名整數常量提供了一種有效的方法。例如,假設您必須定義乙個變數,該變數的值表示一周中的一天。該變數只能儲存七個有意義的值。若要定義這些值,可以使用列舉型別。列舉型別是使用 enum 關鍵字宣告的。enum days 如果未在列舉數列表中指定元素...

POJ Candies 差分約束 spfa 水題

前置知識spfa,差分約束 不會的建議先去做 洛谷p1993 最開始用佇列,不知道為什麼超時了,看別人的部落格把佇列換成棧就行了。我也這樣換一下,不太懂。code include include include include include include using namespace std ...