随笔分类 - 算法
摘要:1 #include <iostream> 2 #include <cstdio> 3 4 using namespace std; 5 6 template <class T> 7 inline void read(T &s) 8 { 9 s = 0; 10 int w = 1; 11 char
阅读全文
摘要:1 #include <bits/stdc++.h> 2 using namespace std; 3 template <class T> 4 inline void read(T &s) 5 { 6 s = 0; 7 int w = 1; 8 char ch = getchar(); 9 whi
阅读全文
摘要:/* https://blog.csdn.net/sugarbliss/article/details/86495945?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522169977002316800215045285%2522%252
阅读全文
摘要:1 #include <bits/stdc++.h> 2 using namespace std; 3 string s1, s2; 4 vector<int> find_next(vector<int> next, string s) 5 { 6 int i = 1, prefix = 0, le
阅读全文
摘要:题解: 模拟棋子移动,最后几行找不到规律所以直接打表 1 #include <bits/stdc++.h> 2 using namespace std; 3 int n; 4 char s[500]; 5 void init() 6 { 7 for (int i = 0; i < n; ++i) 8
阅读全文
摘要:1 #include <bits/stdc++.h> 2 using namespace std; 3 int k, x, y; 4 5 int judge(int x, int y, int gx, int gy, int len) // 判断障碍物在哪个区块 6 { 7 if (gx <= x
阅读全文
摘要:题解: 利用快速排序的思想来寻找第k小的数,可以避免很多不必要的操作 1 #include <bits/stdc++.h> 2 using namespace std; 3 const int N = 5000005, M = 5e6 + 5; 4 int x[N], k; 5 inline int
阅读全文
摘要:题解: 这道题最大的坑:32 和 321,32321 > 32132 1 #include <bits/stdc++.h> 2 using namespace std; 3 string a[25]; 4 bool cmp(const string &a, const string &b) 5 {
阅读全文
摘要:题解: 这道题的关键是找到状态转移方程,从最底层(n)开始,计算上面全部(n, n - 1, n - 2 …… 1)层的总表面积和总体积,从而来确定使表面积最小的S 1 #include <bits/stdc++.h> 2 using namespace std; 3 #define S(r) ((
阅读全文
摘要:题解: 这段代码实现了一个递归的记忆化搜索算法,用于解决一个求最大蛋糕面积下限的问题。下面解释一下其递归思路: 定义状态 设 ways[w][h][m] 表示当前蛋糕的宽度为 w,高度为 h,已经切了 m 刀时,最大蛋糕面积的下限。 状态转移 对于当前的蛋糕,可以选择竖着切一刀或者横着切一刀。竖着切
阅读全文
摘要:题解: 1 #include <bits/stdc++.h> 2 using namespace std; 3 const double ex = 1e-6; 4 double a[5]; 5 bool iseq(double a, double b) 6 { 7 return fabs(a - b
阅读全文
摘要:题解: 1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 #include <cmath> 5 #include <cstring> 6 #include <vector> 7 #include <map> 8 #i
阅读全文
摘要:题解: 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int main() 5 { 6 string init, result; // 要操作的,预期的 7 string temp; // 记录当前状态 8 cin >> init >>
阅读全文
摘要:题解: 思路:将A~L每个字母都枚举一遍(每个字母都有轻和重两种状态),看看是否符合输入数据条件 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 string Left[3], Right[3], Result[3]; 5 6 bool c
阅读全文
摘要:记忆化搜索 ——即把搜过的地方记录下来,后面再搜的时候直接取就好了 题解: 1 #include <iostream> 2 using namespace std; 3 #define ll long long 4 const int N = 100; 5 ll a[N], n; 6 ll dfs(
阅读全文
摘要:题解: 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 bool d[100]; // 记录棋盘主对角线能否放 5 bool c[100]; // 副对角线 6 bool b[20]; // 列 7 8 int a[20]; 9 10 //
阅读全文
摘要:题解: 1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 #include <cmath> 5 #include <cstring> 6 #include <vector> 7 #include <map> 8 #i
阅读全文
摘要:这道题真是费了我好大力气(估计我还会回来看不少次qwq) 题解(DFS): 每个钟有4种情况,暴力枚举49种情况,这里只要一维数组就可以记录钟的状态(nowClock[] 和 oriClock[]) 1 #include <bits/stdc++.h> 2 using namespace std;
阅读全文

浙公网安备 33010602011771号