- 博客(20)
- 收藏
- 关注
原创 四川省赛 E.Don‘t Really Like How The Story Ends(贪心dfs)
四川省赛 E.Don‘t Really Like How The Story Ends(贪心dfs) #include<bits/stdc++.h> using namespace std; //定义部分 const int maxn = 1e5+100; int t,n,m,u,v,ans,tot; //变量tot计算当前遍历到哪一个数 vector<int>edge[maxn]; void dfs(int u) { if(u == n+1) return;
2021-09-14 19:47:28
683
原创 2021-08-06
简单概率练习 离散型概率 简单的公式: 条件概率公式:P(A|B) = P(AB) / P(B) 贝叶斯公式:P(A|B) = P(B|A) * P(A) / P(B) UVA1636 //UVA1636 普通分析概率性问题 #include<iostream> using namespace std; int a,b,n; int main() { string str; while(cin>>str) { a=b=n=0;
2021-08-06 23:38:26
231
原创 尺取法技巧练习题及解答
题目链接在代码头部(自取) //https://vjudge.net/problem/POJ-3320 #include<iostream> #include<map> #include<set> using namespace std; const int maxn = 1e7; set<int>s; map<int,int>m; int a[maxn]; int n,sum,len,l,r,ans; int main() { ios::
2021-04-28 21:09:01
1627
原创 高精度算法模板
java 高精度 import java.util.Scanner; import java.math.BigInteger; public class Main { public static void main(String[] arge){ Scanner cin=new Scanner(System.in); //int T=cin.nextInt(); //for(int i=0;i<T;i++){ BigIntege
2021-03-26 12:14:14
225
原创 2021-03-16
a add, subtract, multiply and divide加减乘除 arithmetic progression 等差数列 average temperature顺时针 anticlockwise 逆时针 b c cube立方 Cube root立方根 clockwise order顺时针方向顺序 counterclockwise 逆时针 contraclockwise逆时针 d divisor 因数 Denominator分母 diagonally 对角线的 D is rounded to
2021-03-16 14:18:37
323
原创 最长上升子序列(LIS)
题目链接 dp数组:dp[maxn];存储数组: a[N]; 求一个长度为N的上升子序列的递推公式: 1.dp[i] : 定义为以a[i]为结尾的(数组下标从 0 开始)序列最大上升子序列的值 2.以a[i]为结尾的最大上升子序列为: (1)a[i] 本身 (2)j < i && a[j]<a[i]以a[j]为结尾的上升子序列,末尾追加a[i]的子序列 由此得出递推公式 dp[i] = max(1,dp[j] +1 | ( j < i &&
2021-01-30 00:33:35
3630
原创 完全背包问题
3. 完全背包问题 题目 提交记录 讨论 题解 视频讲解 有 NN 种物品和一个容量是 VV 的背包,每种物品都有无限件可用。 第 ii 种物品的体积是 vivi,价值是 wiwi。 求解将哪些...
2021-01-24 16:11:27
166
原创 0-1背包问题
HDU 2602 #include<stdio.h> #include<string.h> struct fly { int v; int w; }z[1007]; int cmp(int a,int b) { return a>b?a:b; } int dp[1007]; int main() { int t,i,j; scanf("%d",&t); while(t--) { int N,
2021-01-23 22:10:21
151
原创 字符串转换为对应整数
题目描述 计算逆波兰式(后缀表达式)的值 运算符仅包含"+" , * " - " , " * " 和 " / “,被操作数可能是整数或其他表达式* 例如: [“20”, “10”, “+”, “30”, " * " ] -> ((20 + 10) * 30) -> 900 [ “40”, “130”, “50”, “/”, “+”] -> (40 + (130 / 50)) -> 42 示例1 输入 [ “20”,“10”,”+",“30”,"*"] 返回值 900 第一.
2021-01-19 20:48:10
1504
原创 二分图判定
第四天 给定一个图,用VECTOR存储判定是否可以用两种颜色染完全图(相邻颜色要求不相同) #include<iostream> #include<vector> using namespace std; vector<int>G[100]; int n,m,color[100]; bool dfs(int v,int c) { color[v] = c; for(int i = 0;i<G[v].size();i++) { //如果相邻边已经
2021-01-14 23:13:38
151
原创 单源最短路狄克斯特拉 + 链式前向星 + 堆 优化
模板 #include<bits/stdc++.h> #include<queue> using namespace std; const int maxn = 1e6; const int INF = (1<<31 -1); int head[maxn],dis[maxn],vis[maxn],n,m,s,cnt; priority_queue<pair<int,int>,vector<pair<int,int> >,great
2021-01-12 20:50:47
181
原创 链式前向星存储图
第七天链式前向星存图 图片如下所示 本代码存的是有向图,图示为无向图。 #include<iostream> using namespace std; const int maxn = 100; struct node//to 边的终点编号,w 权值, next 以 x 为起点的上一条边的编号 { int to,w,next; }e[maxn]; //head[]数组下标表示起点编号,head[]数组里面的值表示在e[maxn]中开始的下标编号 int cnt, head[maxn];
2021-01-10 23:20:20
1081
原创 单源最短路径问题(狄克斯特拉算法)
挑战程序设计竞赛2上的一道例题 P250 #include<iostream> using namespace std; static const int MAX = 100; static const int INFTY = (1<<21); /这里表示int类型最大值 static const int WHITE = 0;//表示三种状态 static const int GRAY = 1; static const int BLACK = 2; //点的个数和邻接矩阵存储方式
2021-01-09 23:30:13
552
1
原创 线段树简介
第三天 线段树主要用于解决求区间和、区间修改、区间最值的问题。 线段树模板 #include<bits/stdc++.h> using namespace std; struct node { int l,r,w,lazy;//tree的l,r表示数组区间[l,r],w表示[l,r]区间和 }tree[400001]; //lazy!=0是加值,lazy!=-1是改值 void build(int v,int l,int r)//建树,v表示tree里第v个结点,tree
2021-01-07 22:48:33
186
原创 堆的建立,及堆排序
第二天 堆的建立 #include<iostream> using namespace std; const int N = 1000; int n,a[N]; void sift(int a[],int k,int n)//k是要调整数值的编号,调整范围是从K到N { int i = k; int j = 2*i; while(j<n) { if(j<n && a[j+1]>a[j]) j++; if(a[i]>a[j]) break;
2021-01-06 20:51:49
187
原创 DFS搜索问题
*(寒假训练第一天) 今日DFS搜索问题如下: 1. P1162 填涂颜色 2. P1605 迷宫 3. P1036 [NOIP2002 普及组] 选数 4. P2392 kkksc03考前临时抱佛脚 (一) 收获最大的还是填涂颜色问题: 题目中数字矩阵有0和1两种数字,要求将1包围的数字0全部变 为2并输出变换后的矩阵; 思考:这里可以将 1 包围的 0 和在外围的 0 ,通过深度优先搜索标记 区分开来,比如将外围的 0 变为3,被包围的 0 不变化即可。 #include<
2021-01-05 22:14:38
269
1
原创 最小生成树
生成树专题 最小生成树不要点我 1.kruskal算法 Kruskal 算法是能够在O(mlogm) 的时间内得到一个最小生成树的算 法。它主要是基于贪心的思想: ① 将边按照边权从小到大排序,并建立一个没有边的图T。 ② 选出一条没有被选过的边权最小的边。 ③ 如果这条边两个顶点在T 中所在的连通块不相同,那么将 它加入图T, 相 同就跳过。 ④ 重复②和③直到图T 连通为止。 由于只需要维护连通性,可以不需要真正建立图T,可以用并查集 来维护。 观察一下几种不同风格的代码 #include&
2020-12-12 16:30:07
775
原创 有关C++数组溢出问题,C++数组可以开多大
一个由C/C++编译的程序占用的内存分为以下几个部分 1、栈区(stack)— 由编译器自动分配释放 ,存放函数的参数值, 局部变量的值等。其 操作方式类似于 数据结构 中的栈。 2、堆区(heap) — 一般由程序员分配释放, 若程序员不释放,程序结束时 可能由OS回 收 。注意它与数据结构中的堆是两回事,分配方式倒是类似于链 表,呵呵。 3、全局区
2020-12-01 21:06:54
846
原创 A problem of sorting有关字符串的一道坑题
A problem of sorting有关字符串的一道坑题@[TOC](A problem of sorting) 这道题目主要对结构体排序,以及对字符串处理能力的考查,题目中姓名可以含有空格是一个坑点,也是问题的关键。 话不多说,看代码。 #include<bits/stdc++.h> using namespace std; struct person { char name[105]; int age; }a[105]; bool cmp(const person a,const
2020-11-30 16:55:12
200
原创 二分查找函数的使用
二分查找函数的使用 lower_bound( )和upper_bound( )都是利用二分查找的方法在一个排好序的数组中进行查找的。 在从小到大的排序数组中, lower_bound( begin,end,num):从数组的begin位置到end-1位置二分查找第一个大于或等于num的数字,找到返回该数字的地址,不存在则返回end。通过返回的地址减去起始地址begin,得到找到数字在数组中的下标。 upper_bound( begin,end,num):从数组的begin位置到end-1位置二分查找第一个大
2020-11-25 08:44:30
1157
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅