随笔分类 - 解题报告
-
AcWing每日一题(提高组)--星空之夜
摘要:https://www.acwing.com/problem/content/1404/ 考察flood fill 和 图的hash。 这题有两问:1、找出图中的全部连通块 2、根据形状给给将相似的连通块换上同一个字符 对于第一问,可以直接应用flood fill算法。 对于第二问,我们可以通过ha 阅读全文
-
AcWing每日一题--数独检查
摘要:https://www.acwing.com/problem/content/705/ 考虑每个独立方块的左上角和右下角。 单独检查每一个独立方块。 1 #include<iostream> 2 #include<unordered_map> 3 using namespace std; 4 con 阅读全文
-
AcWing每日一题--开心的金明
摘要:https://www.acwing.com/problem/content/428/ 给定总钱数n,和m个物品,每个物品有价格和重要度两个属性。 问在总价格不超过n的情况下,选中物品的价格*重要度的和最大是多少。 可以抽象为01背包模型,总钱数为背包容量,价格为物品体积,价格*重要度为物品价值。 阅读全文
-
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 阅读全文
-
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 阅读全文
-
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 阅读全文
-
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 阅读全文