洛谷P1540 [NOIP2010 提高组] 机器翻译(队列) #include<iostream>using namespace std;int m[1001], first, last, M, N, num;int main() { cin >> M >> N; for (int i = 0; i < N; i++) { int w, j; cin >> w; for (j = first; j < last && m[j] != w; j++) {} if
洛谷P1160 队列安排(双向队列) #include<iostream>using namespace std;constexpr int MAXSIZE(100000);struct Deque { int left, right; bool isDeleted;}deque[MAXSIZE + 1];int main() { deque[0].right = 1; deque[1].left = 0; int N; cin >> N; for (int i = 2; i <= N
洛谷P1996 约瑟夫问题进阶解法 #include<iostream>constexpr int MAXSIZE(100);using namespace std;int a[MAXSIZE + 1], n, m;int main() { cin >> n >> m; for (int i = 0; i < n; i++) a[i] = i + 1; a[n] = 1; for (int i = 1, cur = 0; i <= n; i++) { for (i
洛谷P1449 后缀表达式进阶解法 #include<iostream>#include<stack>#include<string>using namespace std;stack <int> expr;string temp;char ch;int first, second;int main(){ for (;;) { cin >> ch; switch (ch) { case('.'): expr.push(stoi(tem
洛谷P3613 【深基15.例2】寄包柜进阶解法 #include<iostream>#include<vector>constexpr int MAX = 10e5 + 1;int n, q;using namespace std;struct Chest{ vector<int>box, item; int num;}chest[MAX];int main(){ cin >> n >> q; for (int i = 0; i < q; i++) {
洛谷P4995 跳跳!进阶解法 #include<iostream>#include<algorithm>using namespace std;constexpr int MAX_LENGTH = 300;int n, h[MAX_LENGTH], g[MAX_LENGTH + 10];long long sum;int main(){ cin >> n; for (int i = 0; i < n; i++) cin >> h[i]; sort(h, h
洛谷P1208 [USACO1.3]混合牛奶 Mixing Milk进阶解法 #include<iostream>#include<algorithm>using namespace std;int const MAX_LENGTH = 5000;int n, m, sum;struct SFarmer{ int p, a;}farmer[MAX_LENGTH];bool compare(const SFarmer& first,const SFarmer& second){ return first.p < s
洛谷P5019 [NOIP2018 提高组] 铺设道路进阶解法 #include<iostream>using namespace std;int const MAX_LENGTH = 100001;int n, d[MAX_LENGTH];long long sum;int main(){ cin >> n; for (int i = 0; i < n; i++) cin >> d[i]; for (int i = 0; i < n - 1; i++) if (d[i] > d[i +
洛谷P1106 删数问题进阶解法 #include<iostream>#include<string>using namespace std;int k;string s;int main(){ cin >> s >> k; for (int i = 0; i < k; i++) { int l = s.length(); for (int j = 0; j < l - 1; j++) if (s[j] > s[j + 1]) {
洛谷P1219 [USACO1.5]八皇后 Checker Challenge进阶解法 #include<iostream>#include<algorithm>using namespace std;int n, number;bool square[14][14];bool isOK[14][14];void dfs(int depth = 1){ if (n + 1 == depth) { number++; if (number <= 3) { for (int i = 1; i <= n; i++)
洛谷P2240 【深基12.例1】部分背包问题进阶解法 #include<iostream>#include<algorithm>#include<iomanip>using namespace std;struct SCoin{ int m, v;}coin[101];int N, T, t;double V;bool myCompare(const SCoin& first, const SCoin& second){ return first.v * second.m >
洛谷P1228 地毯填补问题进阶解法 #include<iostream>#include<cmath>using namespace std;int k, x, y;void cover1(int k, int d, int m, int n){ int N = pow(2, k); if (k == 0) { cout << m + 1 << ' ' << n + 1 << ' '; switch (d) { case(1):cout
洛谷P1259 黑白棋子的移动进阶解法 #include<iostream>using namespace std;int N;int main(){ cin >> N; for (int i = N; i > 3; i--) { for (int j = 0; j < i; j++) cout << 'o'; for (int j = 0; j < i; j++) cout << '*'; cout << "--"; fo
洛谷P1990 覆盖墙壁进阶解法 #include<iostream>using namespace std;int a[1000001], b[1000001], N;int main(){ cin >> N; a[1] = 1; b[1] = 1; a[2] = 2; b[2] = 2; for (int i = 3; i <= N; i++) { a[i] = (a[i - 1] + 2 * b[i - 2] + a[i - 2]) % 10000; b[i] = (a[
洛谷P1164 小A点菜进阶解法 #include<iostream>using namespace std;int N, M, a[1000], b[1000][10000];int main(){ cin >> N >> M; for (int i = 1; i <= N; i++) cin >> a[i]; b[0][0] = 1; for (int i = 1; i <= N; i++) for (int j = 0; j <= M; j+
洛谷P2437 蜜蜂路线进阶解法 #include<iostream>#include<string>using namespace std;int M, N;string first = "0", second = "1", third = "";void factorial(){ int temp; for (int i = 0; i < N; i++) { temp = 0; third.clear(); for (int j = 0; j < first.leng