03 2023 档案

摘要:#include<iostream> using namespace std; const int N=1e4+10; int a[N]; int st[N];//标记数组 int n,k; int main(){ cin>>n>>k; for(int i=0;i<n;i++){ cin>>x; i 阅读全文
posted @ 2023-03-17 17:55 chenxinyue 阅读(25) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; int main(){ double n; cin>>n; int l=1,r=n; while(l+1e-7<r){ double mid=(l+r)/2; if(mid*mid*mid>=n){ r=mid;}els 阅读全文
posted @ 2023-03-17 17:41 chenxinyue 阅读(48) 评论(0) 推荐(0)
摘要:#include<bits/stdc++.h> using namespace std; int n,m; int l,r; const int N=1e5+10; int a[N]; int main(){ cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i]; 阅读全文
posted @ 2023-03-17 16:47 chenxinyue 阅读(11) 评论(0) 推荐(0)
摘要:#include<iostream> #include<cstring> #include<queue> using namespace std; int n,m; int e[N],ne[N],idx,h[N]; int q[N];//队列 void add(int a,int b){ e[idx 阅读全文
posted @ 2023-03-16 22:51 chenxinyue 阅读(81) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; int n; const int N=1e5+10; int e[N*N],ne[N*N],idx,h[N];//注意要开N*N的大小 bool st[N];//标记数组 标记一下这个节点是否被走过 true即为被走过 阅读全文
posted @ 2023-03-16 22:16 chenxinyue 阅读(34) 评论(0) 推荐(0)
摘要:#include<iostream> #include<cstring> #include<unorderd_map> const int N=10; int d[N]; using namespace std; int dfs(string start){ string end="12345678 阅读全文
posted @ 2023-03-16 21:58 chenxinyue 阅读(29) 评论(0) 推荐(0)
摘要:#include<iostream> #include<cstring> #include<queue> const int N=110; int n,m; typedef pair<int,int> PII; int g[N][N];//存图 int d[N][N];//记录距离 PII q[N* 阅读全文
posted @ 2023-03-16 21:24 chenxinyue 阅读(30) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; const int N=20;//N*N 两倍 int n; bool col[N],dg[N],udg[N];//同一列,对角线,反对角线(标记一下是否可以走) //udg 副对角线 ///英语单词 column 列 阅读全文
posted @ 2023-03-14 20:39 chenxinyue 阅读(41) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; const int N=10; bool st[N];//记录数字是否被使用 int path[N];//输出所有可能的组合 int n; int dfs(int u){//u表示深度 if(u>n){ for(int 阅读全文
posted @ 2023-03-14 20:17 chenxinyue 阅读(22) 评论(0) 推荐(0)
摘要:重点:将队列中没有用的元素删除。 如果在窗口中存在i<j,ai>aj,那么在窗口向右移动的过程中,只要aj存在,那么ai就永远不可能成为最小值。应该被移除。 因此,当窗口移动到aj的那一刻,ai以及窗口中一切大于或者等于aj的元素都应该被移出队列。形成一个单调递增的队列,找队首就是最小值。找最大值的 阅读全文
posted @ 2023-03-13 22:48 chenxinyue 阅读(29) 评论(0) 推荐(0)
摘要:这一题的思想是这样,1,2,3,4,5,6,7,8,9,10.遍历数组,先把i的倍数全部删掉,因为如果是谁的倍数那么肯定就不是质数,把所有的倍数都删掉以后,剩下的就是质数了。比如,1肯定不是质数了,2的倍数是4,删掉4,3的倍数是6,是9,删掉6,9,4的倍数是8,删掉8,5的倍数是10,删掉10, 阅读全文
posted @ 2023-03-13 21:36 chenxinyue 阅读(39) 评论(0) 推荐(0)
摘要:#include<iostream> #include<algorithm> using namespace std; int divide(int n){//输出底数和指数 for(int i=2;i<=n/i;i++){//可以发现,n中最多只有一个大于sqrt(n)的因子。通过反证法:如果有两 阅读全文
posted @ 2023-03-13 21:16 chenxinyue 阅读(36) 评论(0) 推荐(0)
摘要:只保证根节点的size是有意义的。 pa=b。b是父节点。size[find(b)]+=size[find(a)];注意判断,如果find(a)==find(b),两个集合已经合并,就不可以让size相加,会导致数量翻倍。 #include<iostream> using namespace std 阅读全文
posted @ 2023-03-11 13:26 chenxinyue 阅读(29) 评论(0) 推荐(0)
摘要:合并集合:1.将两个集合合并2.询问两个集合是否在一个集合中 如何求树根的编号:往上走 如何合并两个集合:px是x的集合编号,py是y的集合编号,合并直接px=y。(给px找了个爸爸,爸爸是y)(让x的祖宗节点的父亲等于y的祖宗节点) #include<iostream> const int N=1 阅读全文
posted @ 2023-03-11 13:02 chenxinyue 阅读(47) 评论(0) 推荐(0)
摘要:单调栈经常用来 找出每个数左边或者右边离它最近的比它大或者小的数 使用单调栈的做法是先将该数左边的数字存入一个栈中,当遍历到当前元素时,首先判断一下栈是否为空,(while)如果栈不为空,就判断一下当前栈顶元素和该数的大小,只要当前的栈顶元素比该数大,就弹出栈顶元素,直到栈为空或者找到一个比当前这个 阅读全文
posted @ 2023-03-09 18:30 chenxinyue 阅读(36) 评论(0) 推荐(0)
摘要:重点:队列是有队头指针hh和队尾指针tt,判断空的条件是如果hh>=tt,队列就为空。 栈只能从一个入口出入,栈底永远在0位置(这个位置不存元素)。但是队列是从队尾t a i l入队,从队头h e a d出队的。所以入队的过程其实会让队尾t a i l 沿着数组索引的增长方向增长,出队的过程则会让队 阅读全文
posted @ 2023-03-09 17:48 chenxinyue 阅读(35) 评论(0) 推荐(0)
摘要:重点:栈是先进后出,从栈顶进,也是从栈顶取。重点是判断空的条件和栈顶下标。 #include<iostream> using namespace std; int tt=0;//栈顶下标 const int N=1e5+10; int stk[N];//栈 int main(){ int m; ci 阅读全文
posted @ 2023-03-09 17:10 chenxinyue 阅读(16) 评论(0) 推荐(0)
摘要:首先要了解几个概念,假定b(n)是a(n)的差分数组。(1)差分数组:b(n)=a(n)-a(n-1),(2)a(i)数组的值是差分数组b(1)-b(i)的和。即前缀和sum(i)。差分数组的前缀和:b(n)+=b(n-1)(3)在b(l)的基础上+c,在b(r+1)的基础上-c,就是在a(l)-a 阅读全文
posted @ 2023-03-09 16:38 chenxinyue 阅读(21) 评论(0) 推荐(0)
摘要:#include<iostream> using namespcae std; const int N=1e4+10; int st[N]; int num=0; int main(){ int n,k; cin>>n>>k; for(int i=1;i<=n;i++){ int x; cin>>x 阅读全文
posted @ 2023-03-09 16:00 chenxinyue 阅读(57) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; const int N=1e5+10; int a[N],st[N]; int num=0; int main(){ int n,q; cin>>n>>q; for(int i=1;i<=n;i++){ cin>>a[i 阅读全文
posted @ 2023-03-09 15:46 chenxinyue 阅读(31) 评论(0) 推荐(0)
摘要://给出一个长度为 n 的序列 a,选出其中连续且非空的一段使得这段和最大。 #include<iostream> using namespace std; const int N=2e5+10;//注意全局常量必须在前面添加const int a[N];//序列a定义成全局变量 int sum[N 阅读全文
posted @ 2023-03-04 21:12 chenxinyue 阅读(234) 评论(0) 推荐(0)