随笔分类 -  算法题

摘要:131. 直方图中最大的矩形 - AcWing题库 视频题解 131. 直方图中最大的矩形(每日一题·春季) - AcWing 单调栈(存放可能作为答案的数,只能越来越大) 求每个数左边最近的比它小的数的下标 基于y总的代码: //对y总视频题解的中的代码,加了一点点注释 #include<bits 阅读全文
posted @ 2023-05-26 00:34 infocodez 阅读(29) 评论(0) 推荐(0)
摘要:3192. 出现次数最多的数 - AcWing题库 13年12月CCF计算机软件能力认证,第1题 第一次提交,数据范围写错了,wa,日常迷糊,太久不写题了。 第二次提交,试图在一次循环内解决,但忘了判断答案是否为最小的数,wa。 真没必要在螺蛳壳里做道场。在简单题里降低时间复杂度,没有什么实际意义, 阅读全文
posted @ 2023-05-25 14:44 infocodez 阅读(22) 评论(0) 推荐(0)
摘要:MT1069 圆切平面 题目描述:n个圆最多把平面分成几部分?输入圆的数量N,问最多把平面分成几块。比如一个圆以把一个平面切割成2块。 不考虑负数,0或者其他特殊情况。 思路: 任意两个圆相交最多有2个交点,n个圆就有2*C(n,2)=n(n-1)个交点。 每个圆上有2(n-1)个交点,因此圆被分割 阅读全文
posted @ 2023-04-20 22:46 infocodez 阅读(184) 评论(0) 推荐(0)
摘要:其他博文(都没怎么写): 算法题若干 - infocodez - 博客园 数据范围(待加): ACM算法比赛常用宏定义、声明定义及其说明 能开long long用long long,能用double用double 整型数据浮点化: 9*(x-32)/5.0 const int N=5; int ba 阅读全文
posted @ 2023-04-20 22:11 infocodez 阅读(26) 评论(0) 推荐(0)
摘要:T221581 T-1 大富翁 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) cin、cout,全局变量对运行时间的影响 cin、cout,全局变量;32ms scanf、printf,全局变量:31ms scanf、printf,局部变量:30ms 32ms代码: #inclu 阅读全文
posted @ 2022-01-24 11:01 infocodez 阅读(169) 评论(0) 推荐(0)
摘要:由数据范围反推算法复杂度以及算法内容 - AcWing 一般ACM或者笔试题的时间限制是1秒或2秒。在这种情况下,C++代码中的操作次数控制在 107∼108 为最佳。 下面给出在不同数据范围下,代码的时间复杂度和算法该如何选择: n≤30, 指数级别, dfs+剪枝,状态压缩dp n≤100 => 阅读全文
posted @ 2022-01-23 15:02 infocodez 阅读(257) 评论(0) 推荐(0)
摘要:刘汝佳《算法竞赛入门经典(第2版)》P41 题面: 用1,2,3,…,9组成3个三位数abc, def和ghi,每个数字恰好使用一次,要求abc:def:ghi = 1:2:3。按照”abc def ghi”的格式输出所有解,每行一个解。提示:不必太动脑筋。 代码:习题2-6排列_threealon 阅读全文
posted @ 2022-01-22 21:37 infocodez 阅读(81) 评论(0) 推荐(0)
摘要:小学题目,但在2021新生赛没能一次性ac,因为第一次没考虑到鸡兔必须为整数。因此这里放一下。 题目很经典,不复述。 输入头n,脚m,求鸡a兔b 解法: a+b=n 2*a+4*b=m a、b必须为非负整数。 代码: #include<stdio.h> int main(){ int a,b,n,m 阅读全文
posted @ 2022-01-19 11:50 infocodez 阅读(39) 评论(0) 推荐(0)
摘要:843. n-皇后问题 - AcWing题库 #include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) using namespace std; const int N=10; int n; char q[N][N]; bool 阅读全文
posted @ 2021-10-06 08:45 infocodez 阅读(56) 评论(0) 推荐(0)
摘要:842. 排列数字 - AcWing题库 #include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) using namespace std; const int N=10; int n; int quene[N]; bool fl 阅读全文
posted @ 2021-10-06 08:05 infocodez 阅读(71) 评论(0) 推荐(0)
摘要:803. 区间合并 - AcWing题库 #include <iostream> #include <vector> #include <algorithm> using namespace std; typedef pair<int, int> PII; void merge(vector<PII 阅读全文
posted @ 2021-07-30 21:38 infocodez 阅读(96) 评论(0) 推荐(0)
摘要:802. 区间和 - AcWing题库 C++ pair的基本用法总结(整理)_sevenjoin的博客-CSDN博客_c++ pair for(auto i : v)遍历容器元素 - ostartech - 博客园 (cnblogs.com) #include <iostream> #includ 阅读全文
posted @ 2021-07-30 16:59 infocodez 阅读(82) 评论(0) 推荐(0)
摘要:799. 最长连续不重复子序列 - AcWing题库 #include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;i++) using namespace std; const int N=1e5+10; int a[N],cnt[N]; 阅读全文
posted @ 2021-07-29 21:35 infocodez 阅读(52) 评论(0) 推荐(0)
摘要:双指针算法的核心目的是将o(n2)优化到o(n) 常见问题分类: (1) 对于一个序列,用两个指针维护一段区间 (2) 对于两个序列,维护某种次序,比如归并排序中合并两个有序序列的操作 如何写:先写模拟,再观察两个指针之间的单调关系。 模板: for (int i = 0, j = 0; i < n 阅读全文
posted @ 2021-07-21 21:16 infocodez 阅读(44) 评论(0) 推荐(0)
摘要:796. 子矩阵的和 - AcWing题库 按自己思路写出来的代码比y总的复杂一些(二维前缀和数组的初始化部分),然后按y总的思路改了一下代码 #include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;i++) #define rpe(i 阅读全文
posted @ 2021-07-16 21:05 infocodez 阅读(63) 评论(0) 推荐(0)
摘要:ios::sync_with_stdio(false); ios_base::sync_with_stdio - C++ Reference (cplusplus.com) 优点是提高 cin>> 的读取速度,缺点是不能再使用 scanf() 输入规模≥一百万,建议使用 scanf() ——yxc 阅读全文
posted @ 2021-07-16 20:36 infocodez 阅读(716) 评论(0) 推荐(0)
摘要:高精度加法: // C = A + B, A >= 0, B >= 0 vector<int> add(vector<int> &A, vector<int> &B) { if (A.size() < B.size()) return add(B, A); vector<int> C; int t 阅读全文
posted @ 2021-07-15 09:45 infocodez 阅读(68) 评论(0) 推荐(0)
摘要:整数二分模板: bool check(int x) {/* ... */} // 检查x是否满足某种性质 // 区间[l, r]被划分成[l, mid]和[mid + 1, r]时使用: int bsearch_1(int l, int r) { while (l < r) { int mid = 阅读全文
posted @ 2021-07-13 17:51 infocodez 阅读(58) 评论(0) 推荐(0)
摘要:788. 逆序对的数量 - AcWing题库 #include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;i++) using namespace std; typedef long long ll; const int N=1e5+10; 阅读全文
posted @ 2021-07-13 00:33 infocodez 阅读(41) 评论(0) 推荐(0)
摘要:787. 归并排序 - AcWing题库 #include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;i++) using namespace std; const int N=1e5+10; int q[N],n,tmp[N]; void 阅读全文
posted @ 2021-07-12 21:45 infocodez 阅读(34) 评论(0) 推荐(0)