随笔分类 - AcWing 每日一题
摘要:思维题 差分数组 先得到 原始温度数组 和 需求温度数组的差值,即我们需要用差分处理的数组,假设为w。 那么问题是如何利用好,相同的那一段,减少这一段的操作数目。 进行差分之后,连续先等的一段就为0了,保证了算法的最优性。 而差分后的正负值,可以理解为对区间进行加减操作(差分的定义),可以保证算法的
阅读全文
摘要:思维 每两个名字之间以 小于等于 相连,如果出现前面的名字字典序大于后面的名字, 可以消除等于情况,即消除不确定性。 需要注意的是,用双重循环遍历的时候,确定第一个名字在位置i,枚举第二个名字位置j;只要从i到j之间有一个链接消除了不确定性,i和j之间的大小关系就会被确定下来。这就是代码中flag的
阅读全文
摘要:签到题 边界处理 #include <bits/stdc++.h> using namespace std; typedef pair<int, int> PII; const int N = 1e3 + 10; int n; int w[N][N]; int st[N][N]; vector<PI
阅读全文
摘要:题目链接 https://www.acwing.com/problem/content/3362/ 难度:签到 小思维 + 边界处理 #include <bits/stdc++.h> using namespace std; int st[5]; int n; int main() { scanf(
阅读全文
摘要:A 暴力 #include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n; int st[N]; int main() { scanf("%d", &n); for (int i = 1; i < n; i++)
阅读全文
摘要:双指针 + unordered_map 具有相同ID的最大奶牛连续段 等价于 只具有两种奶牛的连续段中的较长的一个 完备性:即使对原来的整个长度多种ID进行删除操作, 中间有第三种ID的位置也无法链接在一起 比如:2352 删除3 或 5,2还是无法链接在一起 所以只需要维护ID为两种的区间即可。
阅读全文
摘要:签到题 字符串模拟二进制加法,因为 X17 = X16 + X1,而 16 倍相当于二进制左移四位,再和本身进行二进制相加即可。 #include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10; int a[N]; int b
阅读全文
摘要:签到 细节处理 答案只可能在 n - 2 个中间节点和 n - 1 个中间节点的中点之间,所以直接枚举这些结果是否条件即可。 但是需要考虑到中点可能是小数,注意 int 和 double 类型的转换。 #include <bits/stdc++.h> using namespace std; //
阅读全文
摘要:枚举 + 贪心 枚举使用优惠卷的礼物,买下,然后每次贪心地选取总花费最小的礼物,知道买不了。 为什么用优惠券一定是对的? 因为 如果有一次买东西的时候,不用优惠卷,那用优惠卷一定不会比这个结果更差;所以,每次只需要枚举使用优惠卷,也即每次枚举一个物品,并用优惠券买下的情况,再贪心。 #include
阅读全文
摘要:简单签到 #include <bits/stdc++.h> using namespace std; // 贪心 const int N = 1e4 + 10; int n; int sum; int x; int w[N]; int main() { scanf("%d", &n); for (i
阅读全文
摘要:水题 #include <bits/stdc++.h> using namespace std; int hh, dd, mm; int fun(int d, int h, int m) { return d * 24 * 60 + h * 60 + m; } int main() { int st
阅读全文
摘要:周日些周六AcWing周赛的三道题。 A 签到题 #include <bits/stdc++.h> using namespace std; int n, k; int w[10]; int main() { scanf("%d %d", &n, &k); for (int i = 1; i <=
阅读全文

浙公网安备 33010602011771号