
C++
是驊哥啊
这个作者很懒,什么都没留下…
展开
-
拓扑排序 ( TopSort )
拓扑排序时间复杂度:O(n+m)因每个结点只需加入队列一次,而每个结点加入队列前需要进行入度数量次的操作,因此时间复杂度为O(n+m)。无法排序?:当有 类似 0 → 1 ,且 1 → 0 ,或 1 → 2 , 2 → 3 ,3 → 1 ,的时候,会形成一个环,导致上一个队列中的元素被移走后,没有入度为0的点,导致 while( ! q.empty ( ) ) 终止,cnt < n核心算法 :void TopSort(){ for(int i = 1; i <= n; i+原创 2021-08-05 21:26:54 · 2733 阅读 · 0 评论 -
DFS BFS 模板
BFSBFS (Breath First Search)广度优先搜索 模板struct jgt{ int x; //横坐标 int y; //纵坐标 int step; //到这一点走的步数}int bfs(){ memset(vis,0,sizeof(vis)); //多组数据需要初始化数组 queue<jgt> q; jgt start,now,next; start.x=sx; //sx为开始点的横坐标 start.y=sy; //sy为开始点的纵坐标 st原创 2021-08-04 21:36:37 · 159 阅读 · 0 评论 -
二进制枚举
C - Skill UpTime Limit: 2 sec / Memory Limit: 1024 MBScore : 300300 pointsProblemTakahashi, who is a novice in competitive programming, wants to learn MM algorithms. Initially, his understanding level of each of the MM algorithms is 00.Takahashi is vi原创 2021-07-27 09:38:29 · 219 阅读 · 0 评论 -
最大公约数 最小公倍数
最大公约数(GCD)辗转相除法(欧几里得算法)int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}最小公倍数(LCM)最小公倍数=两数之积 / 最大公约数lcm(a,b) = a*b / gcd(a,b)int lcm(int a,int b){ return a*b/gcd(a,b);}...原创 2021-07-25 09:49:41 · 75 阅读 · 0 评论 -
快速幂 快速乘 矩阵快速幂
快速幂并取余typedef long long LL;ll Quuickpower(ll a,ll b,ll c){ ll res=1%c; //应对b=0,c=1的特殊情况 while(b) { if(b&1) res=res*a%c; a=a*a%c; b>>=1; } return res;}原创 2021-07-25 09:41:26 · 123 阅读 · 0 评论 -
素数筛(埃氏筛+欧拉筛)
埃氏筛const int N=1000001;bool isPrime[N];void aiPrime(){ memset(isPrime,1,sizeof(isPrime)); isPrime[1]=0; for(i=2;i<=1000000;i++) { if(isPrime[i]) { for(j=i*i;j<=n;j+=i) isPrime[j]=0; } }}欧拉筛const int N=1e6+5;int Prime[N];boo原创 2021-07-25 09:28:22 · 84 阅读 · 0 评论 -
对顶堆(大根堆+小根堆)优先队列
C - Running Median (HDU - 3282)For this problem, you will write a program that reads in a sequence of 32-bit signed integers. After each odd-indexed value is read, output the median (middle value) of the elements received so far.InputThe first line of i原创 2021-07-20 09:01:19 · 363 阅读 · 0 评论 -
大数相加(简单模拟)
1. A + B Problem II(HDU1002)#include<cstring> using namespace std;const int N=1010;int lenmax,lena,lenb,T,i,sum,jin=0,cnt=1;string A,B;int a[N],b[N],c[N];int main(){ cin>>T; while(T--) { cin>>A>>B; lena=A.size();原创 2021-07-17 10:14:33 · 93 阅读 · 0 评论 -
查知识点(供自己用的,有很多地方可能不对,忘大佬斧正小蒟蒻)
二分法查找#include<iostream>#include<cstdio>using namespace std;int a[1000005];//二分函数在此int erfen(int T[],int gei,int num){ int left,right,mid; left=0; right=num-1; while(left<=right) { mid=(right+left)/2; if(gei==T[mid]) return原创 2020-12-20 21:19:20 · 185 阅读 · 0 评论 -
C++判断欧拉图
将无向图用矩阵的方式输入,判断其是欧拉图、半欧拉图还是普通图输入:40 1 1 01 0 0 11 0 0 10 1 1 0输出:欧拉图输入:40 1 1 11 0 0 11 0 0 11 1 1 0输出:半欧拉图输入:80 1 1 1 0 0 0 01 0 0 1 0 0 0 01 0 0 1 0 0 0 01 1 1 0 0 0 0 00 0 0 0 0 1 1 00 0 0 0 1 0 1 10 0 0 0 1 1 0 10 0 0 0 0 1 .原创 2021-05-20 17:25:40 · 1509 阅读 · 1 评论 -
STL基本函数
sort结构体排序:struct jgt{ string s,m,x,h; int id;}a[1000005];bool cmp(jgt f1,jgt f2){ if(f1.s.length()!=f2.s.length()) return f1.s.length()<f2.s.length(); else if(f1.s!=f2.s) //短的在前,同样长度按照字典序小的在前,同用户 return f1.s<f2.s; //名先输入的在前面 else .原创 2021-01-23 18:11:07 · 127 阅读 · 0 评论 -
算法
数字反转:(把数字前面的0自动过滤)int n; cin >> n; int r = 0; while ( n ) { r = r * 10 + ( n % 10); n /= 10; } cout << r;原创 2021-01-22 23:14:48 · 92 阅读 · 0 评论 -
字符串
gets()函数得到可包含空格的字符串,以回车结束;puts()函数输出字符串。原创 2021-01-21 20:50:52 · 110 阅读 · 0 评论 -
C++函数
cmath:ceil()向上取整 1.2 >>> 2floor()向下取整 1.2 >>> 1round()对浮点数四舍五入 1.4 >>> 1 , 1.5 >>> 2原创 2021-01-20 16:23:16 · 90 阅读 · 0 评论