原创 printf的%.xlf 四捨五入保留問題

c的printf中對於小數會進行四捨五入,但是 有問題 例如 printf("%.1lf,%.1lf",1.55,2.55); 結果爲 1.6,2.5 所以 加上一個特別小的數就可以了 或者可以用函數,四捨五入函數 roun

原创 二維KMP模板

#include<bits/stdc++.h> using namespace std; const int maxn=1e3+5; int dp[maxn][256]; void kmp(string pat){ int x

原创 c++的深入學習

c++輸入輸出提速 std::cin.tie(nullptr); 解除的是C++運行庫層面的對數據傳輸的綁定 std::sync_with_stdio(false); 這個函數是一個“是否兼容stdio”的開關,C++爲了兼容C

原创 Tourist's Notes

洛谷題目 鄭航CoderOJ 首先一個很明顯的思路就是,從每個輸入的點開始,往兩邊遍歷。但是要保證每次遍歷不管從那邊開始,最終都要相遇,且相遇時候相等或相差1。 所以用一個優先隊列,每次從最小的開始遍歷就可以了。 但是時間複雜度很

原创 【DP】【狀壓DP】

玉米田 #include<bits/stdc++.h> using namespace std; const int mod = 100000000; int b[20][20] = {0}, f[20][1 << 15] =

原创 【DP】【樹形DP】保安站崗

題目 #include<bits/stdc++.h> #define rep(i, a, b) for(int i = a; i <= b; ++i) using namespace std; const int maxn =

原创 【DP】【樹形DP】有線電視網

題目 #include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;++i) using namespace std; const int maxn=3e3+3; int

原创 棋盤方格

題目 【算法分析】 1.計算正方形的個數s1 邊長爲1的正方形個數爲nm 邊長爲2的正方形個數爲(n-1)(m-1) 邊長爲3的正方形個數爲(n-2)(m-2) ………… 邊長爲min{n,m}的正方形個數爲(m-min{n,m}

原创 【DP】不同路徑

題目 用long long 中間有數據越界 class Solution { public: int uniquePathsWithObstacles(vector<vector<int>>& ob) {

原创 【DP】四鍵鍵盤

最優按鍵序列⼀定只有兩種情況: 要麼⼀直按 A :A,A,…A(當 N ⽐較⼩時)。 要麼是這麼⼀個形式:A,A,…C-A,C-C,C-V,C-V,…C-V(當 N ⽐較⼤時)。 因爲字符數量少(N ⽐較⼩)時, C-A C-C

原创 【DP】【樹形DP】打家劫舍

打家劫舍2 題目 class Solution { public: int get(vector<int>& nums,int l,int r){ int r1=0,r2=0; for(in

原创 【DP】分割等和子集

題目 也可以用DFS做,更快 class Solution { public: bool canPartition(vector<int>& nums) { int sum=0; for(a

原创 【DP】正則表達式匹配

題目 記憶化搜索 class Solution { public: int f[1005][1005]; bool dfs(string s,string p,int l1,int l2,int i,int j){

原创 【DP】三角形最小路徑和

題目 class Solution { public: int minimumTotal(vector<vector<int>>& triangle) { int row=triangle.size();

原创 【DP】最長有效括號

題目 動態規劃 class Solution { public: int longestValidParentheses(string s) { int dp[100005]={0}; in