01 2021 档案
-
leetcode周赛 226
摘要:A:模拟题,枚举每一个数,然后求出他应该放在哪一个盒子里面,时间复杂度为n*lgn 1 class Solution { 2 public: 3 int countBalls(int l, int r) { 4 vector<int> cnt(50,0); 5 int res=0; 6 for(in 阅读全文
-
Educational Codeforces Round 103
摘要:A:题意是给定n,k,求一个包含n个正整数的序列,满足序列和能够整除k,输出该序列最小的最大值。 如果n<=k,res等于k/n+(k%n != 0) 如果n>k,那么需要将k乘上一个数z,使得k>=n。而这个z=n/k+(n%k != 0),之后再进行上述操作。 1 #include<iostre 阅读全文
-
AcWing每日一题--最大的和
摘要:https://www.acwing.com/problem/content/128/ 考察二位前缀和知识。 应用容斥定理写出计算公式,O(1)时间计算子矩形的和。 可以直接枚举每个子矩形的左上和右下角。时间O(n^4),1<=n<=100 故时间合格。 1 #include<iostream> 2 阅读全文
-
AcWing每日一题--摘花生
摘要:https://www.acwing.com/problem/content/1017/ 1 #include<iostream> 2 using namespace std; 3 const int N=110; 4 int w[N][N],f[N][N]; 5 int main(void){ 6 阅读全文
-
AcWing每日一题--火星人
摘要:https://www.acwing.com/problem/content/description/422/ 求全排列的字典序的下一个排列 。 可以直接用STL中的next_permutation。 1 #include<iostream> 2 #include<vector> 3 #includ 阅读全文
-
AcWing每日一题--合唱队形
摘要:1、DP写法 f [ i ] 表示以 i 结尾的子序列的最长长度。 g [ i ] 表示从尾部出发,以 i 结尾的子序列的最长长度。 那么假设选定 i 为最高点的话,合唱队形人数为f [ i ] + g [ i ] - 1 ,减一是因为 i 算了两次。 1 #include<iostream> 2 阅读全文
-
动态规划--线性DP-1
摘要:线性DP:在线性空间上进行答案的递推。 1、数字三角形问题 https://www.acwing.com/problem/content/900/ 1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 const int 阅读全文
-
AcWing每日一题--整数集合划分
摘要:https://www.acwing.com/problem/content/1605/ 1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 typedef long long LL; 5 const int N=1 阅读全文
-
AcWing每日一题--滑雪场设计
摘要:https://www.acwing.com/problem/content/1355/ 性质:最优方案的所有山峰高度一定在[0 , 100]区间内。 所以可以直接枚举最终区间,计算花费,取最小花费即可。 1 #include<iostream> 2 using namespace std; 3 c 阅读全文
-
AcWing每日一题--阶乘
摘要:https://www.acwing.com/problem/content/1383/ 1 #include<iostream> 2 using namespace std; 3 int main(void){ 4 int n; 5 cin>>n; 6 int res=1; 7 int d2=0, 阅读全文
-
AcWing每日一题--货币系统
摘要:https://www.acwing.com/problem/content/1373/ 1、暴搜写法超时 1 #include<iostream> 2 using namespace std; 3 const int N=30; 4 int a[N]; 5 int v,n; 6 int res=0 阅读全文
-
leetcode周赛 255
摘要:https://leetcode-cn.com/contest/weekly-contest-225/ A:枚举,或者可以找规律 解法一:枚举 1 class Solution { 2 public: 3 bool check(char * a,string& b){ 4 for(int i=0;i 阅读全文
-
AcWing每日一题--十三号星期五
摘要:https://www.acwing.com/problem/content/1343/ 按天枚举 1 #include<iostream> 2 using namespace std; 3 int months[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 阅读全文
-
AcWing每日一题--找硬币
摘要:https://www.acwing.com/problem/content/1534/ 算法一:hashmap 对于每一个数a,看m-a是否出现过。取其中的a最小的值。 1 #include<iostream> 2 #include<unordered_set> 3 #include<algori 阅读全文
-
AcWing每日一题--翻硬币
摘要:https://www.acwing.com/problem/content/1210/ 贪心,直接枚举源串,若和目标串不同,则进行操作。 两个性质:最多n-1种操作 每种操作执行0次或者1次 1 #include<iostream> 2 using namespace std; 3 void ch 阅读全文
-
AcWing每日一题--奖学金
摘要:考察排序。 https://www.acwing.com/problem/content/431/ 1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 const int N=310; 5 struct node{ 阅读全文
-
AcWing每日一题--校门外的树
摘要:https://www.acwing.com/problem/content/424/ 1、直接模拟 1 #include<iostream> 2 using namespace std; 3 const int N=10010; 4 bool a[N]; 5 int main(void){ 6 i 阅读全文
-
动态规划--分组背包
摘要:状态表示 f[i][j] 集合:考虑前 i 组物品,体积不超过 j 的取法的价值的集合 属性:最大值 状态计算:f ( i , j ) = f ( i-1 , j) , f ( i-1 , j-v1) + w1 , f ( i , j ) = f ( i-1 , j-v2) + w2 .....最大 阅读全文
-
AcWing每日一题--分巧克力
摘要:https://www.acwing.com/problem/content/1229/ 这个问题也是不好直接求值,但是给定值很好判定这个值是不是可以的,所以也可以用二分解决。 不过整数二分略微有点难写。 1 #include<iostream> 2 #include<climits> 3 usin 阅读全文
-
AcWing每日一题--剪绳子
摘要:https://www.acwing.com/problem/content/682/ 直接求答案并不好求,但是如果给定确定的绳子的长度,问是否能够剪出这么多根是可以在O(n)的复杂度内求出来的。 所以可以将求值问题转化为一个判定问题,这样就可以使用二分来做了。 1 #include<iostrea 阅读全文
-
AcWing每日一题--回文平方
摘要:https://www.acwing.com/problem/content/1348/ 主要考察进位制的转换,数据范围较小,所以并不需要考虑时间复杂度的问题。 1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 c 阅读全文
-
AcWing每日一题--红与黑
摘要:https://www.acwing.com/problem/content/1115/ Flood Fill算法,对于格子问题,求连通块的最大数量 有两种写法,BFS和DFS BFS 1 #include<iostream> 2 #include<queue> 3 #include<cstring 阅读全文
-
AcWing每日一题--蛇形矩阵
摘要:https://www.acwing.com/problem/content/758/ 模拟题 1 #include<iostream> 2 using namespace std; 3 const int N=110; 4 int a[N][N]; 5 int u[]={-1,0,1,0}; 6 阅读全文
-
AcWing每日一题--数字三角形
摘要:https://www.acwing.com/problem/content/900/ 典型的DP问题,状态表示f[i][j] 集合:所有从顶部走到当前位置的路径上的数字和的集合 属性:最大值 状态计算:f [ i ] [ j ]= max ( f[i-1][j-1] , f[i-1][j] )+a 阅读全文
-
AcWing每日一题--货仓选址
摘要:题目:https://www.acwing.com/problem/content/106/ 贪心,将商店从0~n-1编号 如果n是奇数,将货仓放在第n/2个商店上就可以了 如果n是偶数,将货仓放在n/2-1和n/2商店之间就可以了 1 #include<iostream> 2 #include<c 阅读全文
-
Codeforces Round #693
摘要:A、长和宽一直除二到奇数就好了 1 #include<iostream> 2 #include<cstring> 3 #include<algorithm> 4 #include<cstdio> 5 #include<queue> 6 #include<vector> 7 using namespa 阅读全文
-
动态规划--多重背包
摘要:题目:https://www.acwing.com/problem/content/4/ 多重背包题意同完全背包,不过多了一个限制,就是每种物品有数目限制。 朴素想法 最朴素的想法就是直接枚举每种物品拿多少个。 1 #include<iostream> 2 using namespace std; 阅读全文
-
动态规划--完全背包
摘要:题目:https://www.acwing.com/problem/content/3/ 完全背包相较于01背包区别在于每种物品的个数是无限的。 按照如上的分析,写出的代码 1 #include<iostream> 2 using namespace std; 3 const int N=1010; 阅读全文
-
动态规划--01背包
摘要:01背包问题 题目https://www.acwing.com/problem/content/2/ 给定n个物品和一个背包,容量为m,每个物品有体积v和价值w两种属性 选择物品装入背包,使得在不超过背包容量的情况下,价值最大。 1 #include<iostream> 2 using namesp 阅读全文