diff --git a/Luogu/SmallerSmallerSmaller/P1241 括号序列.cpp b/Luogu/SmallerSmallerSmaller/P1241 括号序列.cpp new file mode 100644 index 0000000..c6997e0 --- /dev/null +++ b/Luogu/SmallerSmallerSmaller/P1241 括号序列.cpp @@ -0,0 +1,11 @@ +#include +#include +using namespace std; +int main(){ + string n; + cin >> n; + for(int i = 0; i < n.size(); i++){ + + } + return 0; +} diff --git a/Luogu/SmallerSmallerSmaller/P1996 约瑟夫问题/deque.cpp b/Luogu/SmallerSmallerSmaller/P1996 约瑟夫问题/deque.cpp new file mode 100644 index 0000000..736f72f --- /dev/null +++ b/Luogu/SmallerSmallerSmaller/P1996 约瑟夫问题/deque.cpp @@ -0,0 +1,22 @@ +#include +#include +using namespace std; + +int main() { + int n, m; + cin >> n >> m; + vector a; + for (int i = 0; i < n; i++) { + a.push_back(i + 1); + } + + int idx = 0; + while (!a.empty()) { + idx = (idx + m - 1) % a.size(); + cout << a[idx] << " "; + a.erase(a.begin() + idx); + } + cout << endl; + return 0; +} + diff --git a/Luogu/SmallerSmallerSmaller/P3156 【深基15.例1】询问学号/map.cpp b/Luogu/SmallerSmallerSmaller/P3156 【深基15.例1】询问学号/map.cpp new file mode 100644 index 0000000..ba43d7e --- /dev/null +++ b/Luogu/SmallerSmallerSmaller/P3156 【深基15.例1】询问学号/map.cpp @@ -0,0 +1,18 @@ +#include +#include +using namespace std; +int main(){ + unordered_map a; + int n, m; + cin >> n >> m; + int tmp; + for(int i = 0; i < n; i++){ + cin >> tmp; + a.emplace(make_pair(i + 1, tmp)); + } + for(int i = 0; i < m; i++){ + cin >> tmp; + cout << a.find(tmp)->second << endl; + } + return 0; +} diff --git a/Luogu/SmallerSmallerSmaller/P3156 【深基15.例1】询问学号/vector.cpp b/Luogu/SmallerSmallerSmaller/P3156 【深基15.例1】询问学号/vector.cpp new file mode 100644 index 0000000..ac00129 --- /dev/null +++ b/Luogu/SmallerSmallerSmaller/P3156 【深基15.例1】询问学号/vector.cpp @@ -0,0 +1,18 @@ +#include +#include +using namespace std; +int main(){ + int n, m; + cin >> n >> m; + vector a; + int tmp; + for(int i = 0; i < n; i++){ + cin >> tmp; + a.push_back(tmp); + } + for(int i = 0; i < m; i++){ + cin >> tmp; + cout << a[tmp + 1] << endl; + } + return 0; +} \ No newline at end of file diff --git a/Luogu/SmallerSmallerSmaller/P4715 【深基16.例1】淘汰赛.cpp b/Luogu/SmallerSmallerSmaller/P4715 【深基16.例1】淘汰赛.cpp new file mode 100644 index 0000000..2161b32 --- /dev/null +++ b/Luogu/SmallerSmallerSmaller/P4715 【深基16.例1】淘汰赛.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include +using namespace std; +struct node{ + int element; + node* left; + node* right; +}; +class tree{ +public: + node* root; + deque> player; + int playernum; + + tree(const deque>& x): player(x), playernum(player.size()){}; + pair winner(){ + deque> tmp(player); + reverse(tmp.begin(), tmp.end()); + for(int i = 0; i < 2 * playernum - 2; i += 2){ + pair m = tmp[i].second < tmp[i + 1].second ? tmp[i + 1] : tmp[i] ; + tmp.push_back(m); + } + return tmp.back(); + } +}; + +int main(){ + deque> m1, m2; + int n; + cin >> n; + int tmp; + for(int i = 0; i < pow(2, n - 1); i++){ + cin >> tmp; + m1.push_back(make_pair(i + 1, tmp)); + } + for(int i = pow(2, n - 1); i < pow(2, n); i++){ + cin >> tmp; + m2.push_back(make_pair(i + 1, tmp)); + } + tree t1(m1), t2(m2); + pair m = t1.winner().second > t2.winner().second ? t2.winner() : t1.winner(); + cout << m.first << endl; +} diff --git a/Luogu/SmallerSmallerSmaller/P4715 【深基16.例1】淘汰赛.exe b/Luogu/SmallerSmallerSmaller/P4715 【深基16.例1】淘汰赛.exe new file mode 100644 index 0000000..33b2019 Binary files /dev/null and b/Luogu/SmallerSmallerSmaller/P4715 【深基16.例1】淘汰赛.exe differ