集训04-06 (c++实现)
生活随笔
收集整理的這篇文章主要介紹了
集训04-06 (c++实现)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
極力推薦《算法筆記》這本書!!!
極力推薦《算法筆記》這本書!!!
極力推薦《算法筆記》這本書!!!
(重要的事情說三遍)
數據結構和算法講的很好,反正我能想到的問題它都給我了答案,代碼中使用c++容器和算法恰到好處,使得代碼通俗易懂并且容易實現,不至于陷于c++的語言細節中,只學過c語言的同學請放心食用,每個代碼平均就3-4行用到c++。數據結構除了樹與圖要自己實現以外其他c++都給予實現,同時樹與圖中的廣度遍歷經常要使用到隊列(qutue),直接調用qutue就可以,如果使用數組模擬隊列實在是勸退。反正《算法競賽入門經典》把我勸退了,(沒有看完不多評價)
我的代碼用c++的特性比較多,不過這些特性真的很好用啊
集訓隊練習04
7-1 旅游記 //這題考了圖的最短路徑,我使用了Floyd算法
7-2 大眾評委大作戰
#include<bits/stdc++.h> using namespace std; int main() {int a, c, flag = 0;vector<int>B;while (cin >> a){for(int i=0;i<a;++i){cin>>c;B.push_back(c);}sort(B.begin(), B.end());B.erase(unique(B.begin(), B.end()), B.end());cout << B.size() << endl;for (auto j : B){if (flag == 1)cout << ' ';cout << j;flag = 1;}cout<<endl;B.clear();flag = 0;}}集訓隊練習05
7-1 找數字
7-2 統計相同數字的個數
#include<bits/stdc++.h> using namespace std; int main() {map<int, int>A;int b, c;cin >> c;for(int j=0;j<c;++j){cin >> b;A[b]++;}for (auto i : A){cout << i.first << ' ' << i.second << endl;}}7-1 大數計算
大數計算是經常出現在競賽題目中的一種情況,c++的實現是用到的字符串string
7-2 集訓隊測試成績管理
#include<bits/stdc++.h> using namespace std; int main() {int a, b, item;int n, m;char l;vector<int>C;while (cin >> a){cin >> b;for (int i = 0; i < a; ++i){cin >> item;C.push_back(item);}for (int j = 0; j < b; ++j){cin >> l >> n >> m;if (l == 'U'){C[n - 1] = m;}else{cout << *max_element(C.begin() + (n - 1), C.begin() + m) << endl;}}C.clear();}}7-3 集訓隊測試成績管理(1000ms)//7-2,7-3代碼一樣
#include<bits/stdc++.h> using namespace std; int main() {int a, b, item;int n, m;char l;vector<int>C;while (cin >> a){cin >> b;for (int i = 0; i < a; ++i){cin >> item;C.push_back(item);}for (int j = 0; j < b; ++j){cin >> l >> n >> m;if (l == 'U'){C[n - 1] = m;}else{cout << *max_element(C.begin() + (n - 1), C.begin() + m) << endl;}}C.clear();}} 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的集训04-06 (c++实现)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《战争机器5》全收集攻略 兵籍牌、挑战币
- 下一篇: 《村长征战团》阿育王好用么 阿育王怎么获