藍橋杯省賽準備 刷題整理

2021-10-01 05:47:31 字數 3009 閱讀 6749

目標:200道題,菜雞如我…

2、bfs

3、dp

4、圖論

5、貪心

1、 遞迴實現指數型列舉 (acwing 92)

#include using namespace std;

int n;

void dfs(int u, int state)

printf("\n");

return;

}dfs(u+1, state);

dfs(u+1, state + (1<3、遞迴實現排列型列舉 (acwing 94)#include #include using namespace std;

int n;

void dfs(vectorpath, int u, vectorvis)

for(int i = 1;i<=n;i++) // 列舉每個位置放哪個數

}}int main()

4、n-皇后問題 (acwing843)#include using namespace std;

const int n = 10;

int n;

char g[n][n];

bool col[n], dg[n], udg[n];

void dfs(int u)

); d[0][0] = 0;

int dx[4] = , dy[4] = ;

while(q.size())

, dy[4] = ;

for(int j = 0;j<4;j++)

int dp[n];

dp[0] = 0;

bool f = false;

for(int i=1;i<=n;i++)

if(a[i]>=0) f = true;

if(f == false) else

}int k =0;

for(int i =1;i<=n;i++)

if(dp[i]>dp[k])

k = i;

cout<1、acwing 849. dijkstra求最短路 i (acwing)#include #include using namespace std;

const int n = 505, inf = 1e9;

int g[n][n], d[n], n;

bool vis[n] = ;

void dijkstra(int s)

vis[u] = true;

for(int v=1;v<=n;v++)

}}int main()

dijkstra(1);

if(d[n] == inf) cout<<"-1"<2、850. dijkstra求最短路 ii (acwing850)堆優化#include #include #include #include using namespace std;

typedef pairpii;

struct node

node(int _v, int _w):v(_v), w(_w){}

};const int n = 100010;

const int inf = 1e9;

vectorg[n];

bool st[n];

int d[n];

void dijkstra(int s)

); while(heap.size())

edges[m];

int bel()

int main()

int spfa()}}

}if(d[n] >= inf / 2) return -1;

else return d[n];

}int main()

int t = spfa();

if(t == -1) cout<<"impossible";

else cout<5、852. spfa判斷負環([acwing](852. spfa判斷負環))#include #include #include using namespace std;

const int inf = 1e9;

const int n = 2010, m = 10010;;

int n,m;

int h[n], e[m], ne[m], w[m], idx;

bool st[n];

int cnt[n], d[n];

void add(int a,int b, int c)

bool spfa()

while(q.size())}}

}return false;

}int main()

if(spfa()) cout<<"yes"<6、854. floyd求最短路(acwing)#include #include using namespace std;

const int n = 220;

const int inf = 1e9;

int d[n][n];

int n,m,k;

void f()

{ for(int i=1;i<=n;i++)

for(int j=1;j<=n;j++)

for(int t =1;t<=n;t++)

if(d[j][i]!=inf&&d[i][t]!=inf&&d[j][i]+d[i][t]1、 檸檬水找零(leetcode 860)

2、 判斷子串行(leetcode 392)

3、 分發餅乾(leetcode 455)

4、 跳躍遊戲(leetcode 55)

5、 跳躍遊戲ii(leetcode 45)

6、 擺動序列(leetcode 376)

7、根據身高重建佇列(leetcode 406)

8、用最少數量的箭引爆氣球(leetcode 452)

9、移掉k位數字(leetcode 402)

10、加油站(leetcode 134)

11、區間選點(acwing 905)

藍橋杯省賽真題 抽籤

x星球要派出乙個5人組成的觀察團前往w星。其中 a國最多可以派出4人。b國最多可以派出2人。c國最多可以派出2人。那麼最終派往w星的觀察團會有多少種國別的不同組合呢?下面的程式解決了這個問題。陣列a 中既是每個國家可以派出的最多的名額。程式執行結果為 defff cefff cdfff cdeff ...

藍橋杯省賽真題詳解

題目描述 問題描述 小藍給學生們組織了一場考試,捲麵總分為100分,每個學生的得分都是乙個0到100的整數。請計算這次考試的最高分 最低分和平均分。輸入格式 輸入的第一行包含乙個整數n,表示考試人數。接下來n行,每行包含乙個0至100的整數,表示乙個學生的得分。輸出格式 輸出三行。第一行包含乙個整數...

藍橋杯省賽及國賽準備心得和經驗

第一次參加藍橋杯 第十一屆 已是大三,今後估計也沒有什麼時間和精力參加這種演算法競賽了,所以我在帶大一師弟的時候奉勸他們盡早參加演算法競賽,畢竟這個沒什麼門檻,一些高中生都能達到很高的水平 我乙個上幼兒園的侄女也報了藍橋杯培訓班 只要會用一門程式語言就可以上手。想來自己有一些心得和經驗可以拿出來分享...