Author: 十七

acwing837. 连通块中点的数量

#include<iostream>#define read(x) scanf("%d",&x)using namespace std;const int MAX=1e5+10;int father[MAX],n,m,x,y,sz[MAX];string op

十七 Published on 2022-01-13

leetcode40. 组合总和 II

思路由于这里每个元素不能重复,所以每次dfs()时要+1,并且为了去重,可以先将元素排序class Solution { public: vector<vector<int>> ans; vector<int>path; vector&lt

十七 Published on 2022-01-13

leetcode39. 组合总和

思路如下:1、遍历数组中的每一个数字。2、递归枚举每一个数字可以选多少次,递归过程中维护一个target变量。如果当前数字小于等于target,我们就将其加入我们的路径数组path中,相应的target减去当前数字的值。也就是说,每选一个分支,就减去所选分支的值。3、当target == 0时,表示

十七 Published on 2022-01-12

acwing1969. 品种邻近

思路在间隔k之间找到一个与id相同的即可,可以联想到滑动窗口。对于开始的每个x入栈,对应的ID[x]++,然后在间隔k之后开始出栈,每次出栈后ID[x]--,若ID[x]不为0说明此时在k之内存在相同品种,更新最值。#include<iostream>#include<queue&

十七 Published on 2022-01-12

acwing143. 最大异或对

#include<iostream>using namespace std;const int N=1e5+10,M=3100010;//一个字符最多需要31位int a[N],son[M][2],idx;void insert(int x){ int p=0; for(in

十七 Published on 2022-01-12

acwing830. 单调栈

#include<iostream>using namespace std;const int N=1e5+10;int sk[N],top;int main(){ int n;cin>>n; while(n--){ int x;cin>&gt

十七 Published on 2022-01-10
十七 Published on 2022-01-10

acwing826. 单链表

#include<iostream>using namespace std;const int N=1e5+10;int head,e[N],ne[N],idx;void init(){//初始化 head=-1; idx=0;}void add_to_head(int x)

十七 Published on 2022-01-06

acwing801. 二进制中1的个数

#include<iostream>using namespace std;int n;int main(){ cin>>n; int x; while(n--){ cin>>x; int res=0;

十七 Published on 2022-01-05
Previous Next