原创 高精度減法

#include<bits/stdc++.h> using namespace std; const int maxn=10005; int a[maxn],b[maxn],c[maxn],ans[maxn]; int lena,lenb

原创 高精度加法

#include<iostream> #include<cstring> #include<algorithm> using namespace std; const int MAXN=10005; int A[MAXN],B[MAXN]

原创 最大公約數和最小公倍數問題

//最小公倍數=兩整數的乘積÷最大公約數 #include<bits/stdc++.h> using namespace std; int ans=0; int gcd(int a,int b){ if(b==0) return

原创 P1908 逆序對

/* 題型:樹狀數組 注意:背誦格式,當前樹狀數組的數目 */ #include<cstdio> #include<algorithm> using namespace std; int n,a[50001],p[50001],tree

原创 P1025 數的劃分

/* 題型:遞歸,排列組合 定義:把一個數N分解爲K份,他的方案數把N-i(1<=i<=M/K)分成k-1份的方案數(之和)相等 注意:g要定義在函數開頭,邊界條件注意 */ #include<bits/stdc++.h> using

原创 P1616 瘋狂的採藥,完全揹包問題

/* 題型:完全揹包 注意:j與0,1揹包反過來即可 */ #include<bits/stdc++.h> using namespace std; struct yao{ int value;int heavy; }a[10000

原创 P1060 開心的金明

/* 題型:0,1揹包 注意:動態轉移方程的寫法 for(int i=1;i<=n;i++) for(int j=high;j>=a[i].price;j--) f[j]=max(f[j],f[j-a[i].price]+a[

原创 P1434 滑雪

/* 題型:記憶化動歸 注意哪裏return,返回的是一個i,j的dp的值 */ #include<cstdio> #include<algorithm> using namespace std; con

原创 P1147 連續自然數和

/* 題型:數段的連加連減問題 注意 起點要小於M/2; */ #include<bits/stdc++.h> using namespace std; int M; int main(){ scanf("%d",&M);

原创 快速冪

#include<iostream> #include<algorithm> #include<cstdio> using namespace std; long long b,p,k,ans; long long qpow(long l

原创 P1182 數列分段Section II

/* 80分做法 題型:二分 注意:範圍爲l<=r,左右區間注意。 */ #include <bits/stdc++.h>//萬能頭文件 using namespace std; int n, m, x, f[100001], p,

原创 P1433 吃奶酪

/* 題型:dfs 注意:預處理,回溯 */ #include<cstdio> #include<cmath> #include<algorithm> using namespace std; int n; double dis[1

原创 P1010 冪次方

#include<iostream> #include<cmath> using namespace std; void cg(int n){ if(n==0){//前面五種特判 return ; }

原创 分治算法之排序和逆序對

今天重新學習了一下分治算法,又溫習了一下快速排序和歸併排序的思路。 歸併排序 【思路】①遞歸到只剩一個元素 ②將序列分成長度相等或接近的兩部分。 ③遞歸——對劃分後的兩部分序列分別進

原创 並查集入門

【簡介】 並查集(Union Find)是一種用於管理分組的數據結構。它具備兩個操作:(1)查詢元素a和元素b是否爲同一組 (2) 將元素a和b合併爲同一組。 核心代碼: 1.查詢代碼 int find(int k){//尋找根節