摘要: 搜索的经典题。 我们要求木根的最小长度,就要是木根的数量尽可能多,可以发现木根的长度一定可以整除所有小木棒的总长度,从小到大枚举这个可能的长度,第一次有解的就是答案。 关心的状态:当前正在拼哪根木棍,拼到什么长度了,以及每个小木棒的使用情况。 考虑剪枝: 1.优化搜索顺序:小木棒长度从大到小枚举; 阅读全文
posted @ 2022-04-29 16:01 YHXo 阅读(87) 评论(0) 推荐(0)
摘要: 开两个数组:to[i][j]表示从i这个位置向下的第2j个圆盘是哪个,f[i][j]表示流满从i这个位置向下的 2j 个圆盘需要多少体积的水。 详情见代码: 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+10; 阅读全文
posted @ 2022-04-22 21:55 YHXo 阅读(49) 评论(0) 推荐(0)
摘要: 维护区间最值的模板题。 1.树状数组 1 #include<bits/stdc++.h> 2 //树状数组做法 3 using namespace std; 4 const int N=5e4+10; 5 int m,ma[N],mi[N],n,c[N]; 6 7 int lowbit(int x) 阅读全文
posted @ 2022-04-22 20:19 YHXo 阅读(27) 评论(0) 推荐(0)
摘要: 有两个问题:求位数和求后500位的数。 求位数:最后减去1对答案的位数是不影响的,就是求2p的位数,直接有公式log10(2)*p+1; 求后500位的数:容易想到快速幂和高精度; 1 #include<bits/stdc++.h> 2 using namespace std; 3 int p,f[ 阅读全文
posted @ 2022-04-22 19:03 YHXo 阅读(56) 评论(0) 推荐(0)
摘要: 对于a[],b[]两个数组,我们应选取其中一个为基准,再运用树状数组求逆序对的方法就行了。 大佬博客:https://www.cnblogs.com/luckyblock/p/11482130.html #include<bits/stdc++.h> using namespace std; typ 阅读全文
posted @ 2022-04-22 17:34 YHXo 阅读(29) 评论(0) 推荐(0)
摘要: 模板题,树状数组加上离散化求逆序对。 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 const int N=5e5+10; 5 int n,a[N],b[N],c[N]; 6 LL ans; 7 阅读全文
posted @ 2022-04-22 15:54 YHXo 阅读(41) 评论(0) 推荐(0)
摘要: 一种矩形切割的做法: 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 const int maxn=1005; 5 struct node{//矩形的结构体 6 LL x1,y1,x2,y2; 7 阅读全文
posted @ 2022-04-16 16:32 YHXo 阅读(107) 评论(0) 推荐(0)
摘要: 这可能是我目前做过的最简单的一道noi题目了...... 先对e=1的处理,用并查集;再对e=0查询,如果这两个在同一集合中,则为“”NO“,最后都满足的话输出”“YES”; 数值很大,用一下离散化就行了。 1 #include<bits/stdc++.h> 2 using namespace st 阅读全文
posted @ 2022-04-16 14:23 YHXo 阅读(46) 评论(0) 推荐(0)
摘要: 分析可知:将起点和终点按照从小到大的顺序排序,对答案不会产生影响 所以此时我们得到一种模拟做法: 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=2e4+10; 4 int n,a[N],b[N],ans; 5 //模拟做 阅读全文
posted @ 2022-04-16 12:38 YHXo 阅读(172) 评论(0) 推荐(1)
摘要: 二维平面上的差分,我们可以对每行处理。 比如我们要把(2,2)(5,5)之间的矩形加上1,可以这样处理。 0 0 0 0 0 0 0 +1 0 0 0 -1 0 +1 0 0 0 -1 0 +1 0 0 0 -1 0 +1 0 0 0 -1 0 0 0 0 0 0 那么这道题就简单了。 1 #inc 阅读全文
posted @ 2022-04-16 11:19 YHXo 阅读(29) 评论(0) 推荐(0)