算法笔记
CyIce
啦啦啦啦
展开
-
1046 Shortest Distance
//// Created by CyIce on 2021/2/25.//#include <stdio.h>#include <algorithm>using namespace std;const int MAXN = 100010;// 记录节点1到节点i的距离,固定一个方向int dis[MAXN] = {0};int total = 0;int distance(int a, int b) { if (a > b) swap(a,原创 2021-02-25 16:05:33 · 85 阅读 · 1 评论 -
1042 Shuffling Machine
//// Created by CyIce on 2021/2/25.//#include <stdio.h>#include <algorithm>using namespace std;struct poker { char type; int num; int order;} pokers[54]p;int order[54];void printPoker(poker p) { printf("%c%d", p.ty原创 2021-02-25 10:41:34 · 73 阅读 · 0 评论 -
1001 A+B Format
//// Created by CyIce on 2021/2/25.//#include <stdio.h>#include <stack>using namespace std;stack<int> S;void toString(int n) { int temp = n < 0 ? -n : n; if (n == 0) S.push(0); while (temp > 0) { S.pus原创 2021-02-25 10:14:45 · 83 阅读 · 0 评论 -
1057 Stack
分析由于题目规定每个元素为105以内的正整数,所以可以使用分块的思想储存数据//// Created by CyIce on 2021/2/24.//#include <stdio.h>#include <stack>#include <algorithm>#include <cstring>using namespace std;const int MAXN = 100010;const int SQRTN = 316;int原创 2021-02-24 14:58:22 · 71 阅读 · 0 评论 -
问题 A: 装箱问题
//问题 A: 装箱问题#include <stdio.h>#include <algorithm>using namespace std;const int MAXV = 20010;int dp[MAXV], V[MAXV];int main() { int n, capcity, ans = 0x7777777; scanf("%d%d", &capcity, &n); fill(dp, dp + MAXV, ca原创 2021-02-07 11:02:40 · 146 阅读 · 0 评论 -
问题 A: 【字符串】最长回文子串
分析由于可能存在多个最长的回文串,此时要求输出最左边的回文串,为了方便,字符串从后往前遍历,保证最后的结果一定是最左边的子串。//最长回文子串#include <stdio.h>#include <iostream>#include <cstring>using namespace std;const int MAXN = 5010;int dp[MAXN][MAXN] = {0};int m[MAXN];int main() { c原创 2021-02-04 10:47:37 · 73 阅读 · 0 评论 -
问题 A: 最长公共子序列
//// Created by CyIce on 2021/2/1.////最长公共子序列#include <iostream>#include <algorithm>#include <string>#include <stdio.h>using namespace std;const int MAXN = 110;//将A下标为i,B下标为j的状态保存在dp[i+1][j+1]中,便于定义边界dp[0][i]和dp[i][0]原创 2021-02-01 10:00:15 · 74 阅读 · 0 评论 -
问题 A: 最长上升子序列
//最长上升子序列#include <stdio.h>#include <algorithm>using namespace std;const int MAXN = 1010;int A[MAXN], dp[MAXN];int main() { int n, ans = 1; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &A[原创 2021-01-31 08:48:43 · 61 阅读 · 0 评论 -
问题 A: 最大连续子序列
//// Created by CyIce on 2021/1/30.////最大连续子序列和#include <stdio.h>const int MAXN = 10010;int N, A[MAXN], dp[MAXN], S[MAXN];int main() { int index; scanf("%d", &N); while (N != 0) { for (int i = 0; i < N; ++i) {原创 2021-01-30 10:54:26 · 59 阅读 · 0 评论 -
最大连续子序列和
//// Created by CyIce on 2021/1/30.////最大连续子序列和#include <stdio.h>#include <algorithm>using namespace std;const int MAXN = 100000;int N,A[MAXN],dp[MAXN]={0};int main(){ int ans; scanf("%d",&N); for (int i = 0; i <原创 2021-01-30 10:22:30 · 72 阅读 · 0 评论 -
问题 A: Fibonacci
//// Created by CyIce on 2021/1/30.//#include <stdio.h>const int MAXN = 40;int f[MAXN] = {0};int fibonacci(int n){ if(n==0) return 0; if(n==1) return 1; if(f[n]==0) f[n] = fibonacci(n-1)+fibonacci(n-2); return f[n];}原创 2021-01-30 10:04:54 · 61 阅读 · 0 评论