算法笔记和刷题
文章平均质量分 76
c1assy
天道酬勤,要自律鸭啊啊啊
展开
-
C++柳诺的stl+模板总结
文章目录string类vectorsetmapstackqueuesorttostringstoi、stod可以将字符串string转化为对应的int型、double型变量string类vectorsetmap如果偶尔刷题时候⽤map或者set超时了,可以考虑⽤unordered_map(或者unordered_set)缩短代码运⾏时间、提⾼代码效率~⾄于⽤法和map、set是⼀样的~stackqueuesorttostringstoi、stod可以将字符串s原创 2022-04-25 23:14:23 · 1652 阅读 · 0 评论 -
力扣&PTA~每天至少三题
文章目录算法双指针平方数之和167.两数之和-输入有序数组Reverse Vowels of a string二分法153. Find Minimum in Rotated Sorted Array数据结构链表easy160.相交链表1165 Block Reversing (25 分)树的深度递归BFS-队列图785.判断二分图207.course schedule 拓扑排序入度+广度优先搜索+队列684.Redundant Connection字符串stl7-2 The Judger (25分)1132原创 2022-03-02 12:34:39 · 781 阅读 · 0 评论 -
CSP往年题解记录
文章目录小中大二十四点小中大#include<bits/stdc++.h>using namespace std;int main(){ int n,i; int a[100000]; scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d",&a[i]); } sort(a+1,a+n+1); if(n%2){ printf("%d %d %d",a[n],a[(n+1)/2],a[1]); } el原创 2021-10-27 20:28:25 · 376 阅读 · 0 评论 -
PTA A1016 Phone Bills&A1095 Cars on Campus
B1016 Phone BillsA long-distance telephone company charges its customers by the following rules:Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a long-di原创 2021-10-01 20:55:05 · 180 阅读 · 0 评论 -
变长数组&结构体sort&string
文章目录PAT1006 Sign In and Sign Out (25 分)1008 Elevator (20 分)**变长数组**PAT1006 Sign In and Sign Out (25 分)#include<bits/stdc++.h>using namespace std;struct Stu{ char s[20]; int a,b;};const int N=1000000;Stu stu[N];bool cmp1(Stu s1,Stu s2原创 2021-09-22 21:13:19 · 171 阅读 · 0 评论 -
CCF往年题解及错误记录
#include <stdio.h>int main() { int n,m,l,i; //int A[250000]; int x; int res[256]={0}; scanf("%d%d%d",&n,&m,&l); for(i=0; i<m*n; i++) { //scanf("%d",&A[i]); scanf("%d",&x); res[x]++; //res[A[i]]++; } printf("%d原创 2021-09-06 20:40:15 · 589 阅读 · 0 评论 -
并查集&好朋友
并查集仅有一个根节点,因此设置isRoot[N]记录根节点的数目#include<cstdio>const int N=110;int father[N];bool isRoot[N];int findFather(int x){ int a=x; while(x != father[x]){ x=father[x]; } //路径压缩 可省 //把 当前查询路径上的所有结点的的父亲都指向根结点 while(a != father[a]){ int z=a; .原创 2021-09-05 15:51:04 · 108 阅读 · 0 评论 -
PTA 甲1092&1001 A+B Format
PTA 1092 To Buy or Not to Buy (20 分)Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However the owner of the shop would only sell the strings in wh原创 2021-09-02 23:51:49 · 164 阅读 · 0 评论 -
动态规划&算法笔记
目录基础概念例子最大连续子序列和最长不下降子序列LIS最长公共子序列最长回文串基础概念状态和状态转移方程重叠子问题最优子结构分治:子问题均不重叠贪心:仅选择了一个子问题例子最大连续子序列和时间复杂度O(n)dp[i]表示以A[i]作为结尾的连续序列的最大和dp[i]=max{A[i],dp[i-1]+A[i]}#include <cstdio>#include <algorithm>using namespace std;const int ma原创 2021-08-27 22:15:22 · 119 阅读 · 0 评论 -
PTA甲级A1052&静态链表
静态链表例题:PTA甲级A1052 Linked List SortingA linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. Now given a linked list,原创 2021-08-27 18:11:33 · 122 阅读 · 0 评论 -
算法笔记: DFS && BFS
algorithm头文件下的函数using namespace std;swap(x,y)reverse(a,a+4) a:数组指针sort(首地址,首地址+1,比较函数)原创 2021-08-25 21:02:51 · 115 阅读 · 0 评论