- 博客(93)
- 资源 (1)
- 收藏
- 关注
原创 L3-003 社交集群 (30 分)(注释详解)
#include<bits/stdc++.h>using namespace std;const int N = 1e5;int f[N],a[N];int n;vector<int> ans,v[N],res;set<int> st;int find(int x){ if(x != f[x]) f[x] = find(f[x]); return f[x];}void Union(int a,int b){ int pa = find(
2022-04-14 19:39:48
674
原创 并查集模版(C++)
#include<bits/stdc++.h>using namespace std;const int N = 1e5;int f[N];//寻找根节点 int find(int x){ if(x != f[x]) f[x] = find(f[x]); return f[x];}//合并两个节点 void Union(int a,int b){ int pa = find(a); int pb = find(b); if(pa != pb){ f
2022-04-14 19:34:13
1043
原创 L2-024 部落 (25 分)(注释详解)
要做出本题需要知道怎么建一个并查集#include<bits/stdc++.h>using namespace std;const int N = 1e5; set<int> s;int f[N];bool root[N];int n;//找到父节点int find(int x){ if(x != f[x]) f[x] = find(f[x]); return f[x];}//合并int Union(int a,int b){ int pa
2022-04-14 19:15:07
657
原创 求组合数C(a,b)代码模版(C++)
int C(int a, int b) //计算C(a,b){ LL res = 1; for(int i = a, j = 1; j <= b; i --, j ++) { res = res * i / j; if(res > n) return res; // 大于n已无意义,且防止爆LL } return res;}...
2022-03-24 20:09:18
2307
原创 L2-038 病毒溯源 (25 分)注释详解
多叉树的遍历类似的题目:L2-031 深入虎穴 (25 分)#include<bits/stdc++.h>using namespace std;const int N = 1e5;vector<int> v[N],temp,ans;int fg[N];int n,root;//cur为当前节点void dfs(int cur){ if(temp.size() > ans.size()){ //如果当前序列长度大于上一次序
2022-03-18 11:42:40
607
2
原创 L2-031 深入虎穴 (25 分)注释详解
#include<bits/stdc++.h>using namespace std;const int N = 1e5+10;vector<int> v[N];int fg[N];int n,k,ans,flag,cnt,root;void dfs(int cur){ if(!v[cur].size()){//到达树的叶子节点 此时记录深度 cnt++; if(ans <= cnt){//如果这次的遍历的深度比上次路径更深就更新深度 an
2022-03-18 10:31:50
556
原创 L2-023 图着色问题 (25 分)注释详解
#include<bits/stdc++.h>using namespace std;const int N = 1e5;vector<int> mv[N];bool vis[N];int main(){ int v,e,k; cin>>v>>e>>k; for(int i=0;i<e;i++){ int a,b; cin>>a>>b; //记录每个节点的邻接点 //a
2022-03-16 21:15:46
563
原创 L2-022 重排链表 (25 分)注释详解
#include<bits/stdc++.h>using namespace std;const int N = 1e5;int first,n;struct per{ int ads; int dt; int nx;};struct per m[N];struct per lt[N];int main(){ cin>>first>>n; for(int i=1;i<=n;i++){ int ads,dt,nx;
2022-03-14 11:57:19
1709
原创 L2-032 彩虹瓶 (25 分)注释详解
废话一堆的题目#include<bits/stdc++.h>using namespace std;int main(){ int n,m,k,flag,cnt; cin>>n>>m>>k; for(int i=1;i<=k;i++){ flag = 1; cnt = 1; stack<int> s; for(int j=1;j<=n;j++){ int t; cin>>t; i
2022-03-14 10:47:47
391
原创 L2-011 玩转二叉树 (25 分)注释详解
#include<bits/stdc++.h>using namespace std;const int N = 100;struct tree{ int data; tree *l, *r;};int pre[N],in[N];//创建数tree* ct(int preL,int preR,int inL,int inR){ if(preL > preR) return NULL; tree* root = new tree; root->
2022-03-11 12:03:37
1097
原创 多线程经典消费者生产者代码实现(Java加锁实现)
Desk类package com.huanghun.demo10;public class Desk { public static int count = 10; public static boolean flag; public static final Object lock = new Object();}消费者Foodie类package com.huanghun.demo10;import sun.security.krb5.interna
2022-03-09 20:01:52
406
原创 Spring整合Mybatis的XML文件
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLo
2022-03-07 16:58:40
218
原创 DAO接口实现的XML文件
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="dao.AccountDao"> <!--配置根据id查询--> <sele
2022-03-07 16:48:59
626
转载 applicationContext基础配置
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="h
2022-03-06 23:31:16
219
原创 L2-033 简单计算器 (25 分)注释详解
#include<bits/stdc++.h>using namespace std;stack<int> s1;stack<char> s2;const int error = -1e5;int cal(int b,int a,char op){ if(op == '+') return a + b; if(op == '-') return a - b; if(op == '*') return a * b; if(op == '/' &
2022-03-05 13:48:01
188
原创 L2-034 口罩发放 (25 分)注释详解
#include<bits/stdc++.h>using namespace std;struct per { string a; string b; int t; int idx;};const int N = 1e5;vector<struct per> v[N];vector<struct per> ans;map<string,int> mp,flag;struct per p;int dd,pp;int t,s;
2022-03-04 17:05:59
414
原创 求解1-n集合的所有子集(C++)
#include<bits/stdc++.h>using namespace std;vector<int> v;vector<vector<int> > ans;int n;void dfs(int cur){ for(int i=cur;i<=n;i++){ v.push_back(i); ans.push_back(v); dfs(i+1); v.pop_back(); } }int main
2022-02-26 10:59:24
606
原创 树状数组(C++实现)
#include<bits/stdc++.h>using namespace std;const int N = 100;int A[N]; int C[N];int n;int lowbit(int x){ return (-x) & x;}//计算从A[1]开始到A[x]的和 即前缀和 int sum(int x){ int ret = 0; while(x > 0){ ret += C[x]; x -= lowbit(x); } r
2022-02-12 16:09:32
517
原创 试题 算法训练 跳马(蓝桥杯)注释详解
#include<bits/stdc++.h>using namespace std;int x[8] = {1, 1, -2, -2, 2, 2, -1, -1};int y[8] = {2, -2, 1, -1, 1, -1, 2, -2};int vis[10][10];int aa,bb,c,d,ans = -1;void dfs(int a,int b,int step){ //剪枝 当ans不为-1时 说明已经存储了最小值 //如果当前递归中步数step还没到终
2022-02-12 09:50:48
1195
原创 小国王(状态压缩dp)
小国王#include<bits/stdc++.h>using namespace std;int n,k;//棋盘行数 国王总数 int cnt;//同一行的合法状态个数 int s[1<<12];//同一行的合法状态集 int num[1<<12];//每个合法状态包含的国王数 long long f[12][144][1<<12]; //f[i,j,a]表示前i行放了j个国王 第i行第a个状态时的方案数 int main(){
2022-02-08 19:09:05
450
原创 股票买卖最多K笔交易(线性dp)
股票买卖最多K笔交易#include<bits/stdc++.h>using namespace std;const int N = 100005; int f[N][105][2];int w[N];int main(){ int n,k; cin>>n>>k; for(int i=1;i<=n;i++) cin>>w[i]; for(int j=0;j<=2;j++) f[0][j][1] = -1e6; for
2022-02-07 21:16:55
244
原创 股票买卖多笔交易(线性dp)
题目#include<bits/stdc++.h>using namespace std;const int N = 100005;int w[N],f[N][2];int main(){ int n; cin>>n; for(int i=1;i<=n;i++) cin>>w[i]; f[1][0] = 0;//第1天无票 利润为0 f[1][1] = -w[1];//第1天有票 利润为买股票花的钱 for(int i=2;i&
2022-02-07 21:02:25
120
原创 高精度减法(易记)
#include<bits/stdc++.h>using namespace std;int a[500], b[500], c[500]; void rv(int arr[], string s){ for(int i=1;i<=s.size();i++) arr[i] = s[s.size()-i] - '0'; }int main(){ string s1,s2; cin>>s1>>s2; rv(a,s1); rv(b,s2)
2022-02-07 11:40:57
191
原创 高精度加法(易记)
#include<bits/stdc++.h>using namespace std;int a[500],b[500],c[500];//逆序存放 void rv(int arr[],string s){ for(int i=1;i<=s.size();i++) arr[i] = s[s.size()-i] - '0';}int main(){ string s1,s2; cin>>s1>>s2; rv(a,s1); rv(
2022-02-07 11:35:03
196
原创 试题 算法训练 数字游戏(蓝桥杯)注释详解
ac代码如下#include<bits/stdc++.h>using namespace std;int a[15],b[15];bool vis[15];int n,sum,flag;//判断是否符合条件 bool jg(int arr[], int num){ int temp = n; while(temp--){ for(int i=1;i<=temp;i++){ arr[i] = arr[i]+arr[i+1]; } } retur
2022-02-07 10:30:07
3743
原创 试题 算法训练 拿金币(蓝桥杯)注释详解
ac代码如下#include<bits/stdc++.h>using namespace std;const int N = 1005;int a[N][N],f[N][N];int main(){ int n,ans=-1; cin>>n; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++) cin>>a[i][j]; } for(int i=1;i<=n;i++){
2022-02-07 09:39:14
835
原创 没有上司的舞会(典型树形dp)
Ural 大学有 N 名职员,编号为 1∼N。他们的关系就像一棵以校长为根的树,父节点就是子节点的直接上司。每个职员有一个快乐指数,用整数 Hi 给出,其中 1≤i≤N。现在要召开一场周年庆宴会,不过,没有职员愿意和直接上司一起参会。在满足这个条件的前提下,主办方希望邀请一部分职员参会,使得所有参会职员的快乐指数总和最大,求这个最大值。输入格式第一行一个整数 N。接下来 N 行,第 i 行表示 i 号职员的快乐指数 Hi。接下来 N−1 行,每行输入一对整数 L,K,表示 K 是 L 的直接
2022-02-05 17:01:13
221
原创 最长公共字串(C++动态规划)
输出长度#include<bits/stdc++.h>using namespace std;char a[10005],b[10005];int f[10005][10005];int main(){ int i,j,ans = -1; int x; scanf("%s %s",&a,&b); for(i=1;i<=strlen(a);i++){ for(j=1;j<=strlen(b);j++){ if(a[i-1] == b[j-
2022-02-01 18:38:22
416
原创 和最大的子序列(C++动态规划)
#include<bits/stdc++.h>using namespace std;int a[100000];int sum[100000];int n;int main(){ int head = 0,tail,ans = -1; cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; //获得以1到i的和 记录在sum数组中 for(int i=1;i<=n;i++) sum[i] = sum[i
2022-02-01 10:05:59
378
原创 最长不下降子序列(C++二分查找)
#include<bits/stdc++.h>using namespace std;int a[100];int b[100];//b中存储的不是最长上升子序列 int len = 1;//字符串长度为1时 最长上升子序列长度为1 //二分查找 int bs(int x){ int l = 1,r = len; int mid; //返回第一个大于x的元素的下标 while(l <= r){ mid = l+(r-l)/2; if(x > b[m
2022-02-01 09:28:16
532
原创 最长不下降子序列(C++动态规划)
#include<bits/stdc++.h>using namespace std;int a[100];int dp[100];//记录状态的数字 int main(){ int n,ans = -10; cin>>n; //当只有一个字符的时候 最长上升子序列为1 for(int i=1;i<=n;i++) dp[i] = 1; for(int i=1;i<=n;i++) cin>>a[i]; for(int i.
2022-02-01 09:26:10
1529
原创 最长上升子序列长度(C++二分查找)
#include<bits/stdc++.h>using namespace std;int a[100];int b[100];//b中存储的不是最长上升子序列 int len = 1;//字符串长度为1时 最长上升子序列长度为1 //二分查找 int bs(int x){ int l = 1,r = len; int mid; //返回第一个大于或等于x的元素的下标 while(l <= r){ mid = l+(r-l)/2; if(x >
2022-02-01 09:08:59
791
原创 最长上升子序列(C++动态规划)
#include<bits/stdc++.h>using namespace std;int a[100];int f[100];int main(){ int n,ans = -10; cin>>n; //当只有一个字符的时候 最长上升子序列为1 for(int i=1;i<=n;i++) f[i] = 1; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=2;i<=n;i+
2022-02-01 08:45:02
1126
原创 两个字符串的最长公共子序列(C++动态规划)
#include<bits/stdc++.h>using namespace std;char a[200];char b[200];int f[201][201];//记录长度char p[201][201];//记录公共字符int m,n;void LCS(){ int i,j; for(i=1;i<=m;i++){ for(j=1;j<=n;j++){ if(a[i-1] == b[j-1]){ //左上方存放的一直是公共字符
2022-01-31 11:49:46
1011
原创 多重背包朴素算法模版(C++)
#include<bits/stdc++.h>using namespace std;const int maxn = 100000;int n,m,dp[maxn];int v[maxn],w[maxn],s[maxn];int main(){ cin>>n>>m; for(int i=1;i<=n;i++) cin>>v[i]>>w[i]>>s[i]; for(int i=1;i<=n;i++
2022-01-29 13:04:21
436
原创 通过中序和后序遍历字符串输出前序遍历(C++)
#include<bits/stdc++.h>using namespace std;void dfs(string in,string post){ if(in.size() > 0){ char root = post[post.size()-1];//从后序遍历得到根结点 cout<<root; int k = in.find(root);//找到根结点在中序遍历字符串中的位置 dfs(in.substr(0,k), post.substr(
2022-01-25 17:23:02
820
原创 快速排序优化(C++)
#include<bit/stdc++.h>using namespace std;int n,a[1000005];void qsort(int l,int r)//应用二分思想{ int mid=a[(l+r)/2];//中间数 int i=l,j=r; do{ while(a[i]<mid) i++;//查找左半部分比中间数大的数 while(a[j]>mid) j--;//查找右半部分比中间数小的数
2022-01-24 22:51:45
208
原创 快速排序(C++)
#include<bits/stdc++.h>using namespace std;int a[5] = {2,3,4,35,50};void swap(int &a,int &b){ int temp = a; a = b; b = temp;}//选取数组最后一个元素作为基准 int partition(int arr[], int low, int high){ int pivot = arr[high]; int i = low; for
2022-01-24 14:45:14
333
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人