原创 codeforces 628E Zbazi in Zeydabad(線段樹||樹狀數組優化)

題目鏈接:【codeforces 628E】 Z-pattern:n*m的方形裏面,第一行、最後一行、 反對角線都是Z 輸入n*m由‘z’和‘.’組成的字符矩陣,問有多少個Z-pattern(1<=n, m<=3000) 直接暴力很容易求

原创 帶權值的並查集

題目鏈接:【POJ 1182】食物鏈 父節點跟子節點之間一共有三種關係,父節點吃子節點,子節點吃父節點,父節點跟子節點是同類,所以用三進製表示 fa[B]=A,rank[B]=0表示與父節點是同類,rank[B]=1表示被父節點吃,ran

原创 藍橋杯 歷屆試題 蘭頓螞蟻 (模擬)

題目鏈接:【歷屆試題 蘭頓螞蟻】 問題描述           蘭頓螞蟻,是於1986年,由克里斯·蘭頓提出來的,屬於細胞自動機的一種。   平面上的正方形格子被填上黑色或白色。在其中一格正方形內有一隻“螞蟻”。   螞蟻的頭部朝向爲:

原创 codeforces 716D. Complete The Graph(最短路)

D. Complete The Graph time limit per test 4 seconds memory limit per test 256 megabytes input standard input

原创 hdu 5873 Football Games

Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s

原创 manacher算法模板

內存較大的: #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <string> using

原创 HDU - 1394【Minimum Inversion Number】 線段樹求逆序數對

這是一個很老很經典的題了。。 題意: 已知一個長度爲n的數列,該數列由數字0~n-1無重複組成,n<5000。 現有一種操作,將數列的第一個數移到最後一個去,最終最得到n個數列。 求這n個數列中,逆序數對的最小對數。 解題思路: 先依次將

原创 AC自動機

知識點詳解 hdu 2222 #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <string> using n

原创 並查集

【一次做cf,用遞歸版的超時了,非遞歸版的就ac了】 遞歸版 #include <bits/stdc++.h> using namespace std; const int N=1e3; int fa[N]; int find(int

原创 codeforces 721C. Journey(dp+拓撲)

C. Journey time limit per test 3 seconds memory limit per test 256 megabytes input standard input output stan

原创 RMQ 區間最值的問題

對於長度爲n的數列A,回答若干詢問RMQ(A,i,j)(i,j<=n),返回數列A中下標在i,j裏的最小(大)值。 void RMQ_init(const vector<int>& A) { int n = A.size(); f

原创 codeforces 1A

【1C. Ancient Berland Circus】    【立體幾何】 三角形面積的幾種求法: 1、s=(1/2)*底*高  2、海倫公式:S = √[p(p-a)(p-b)(p-c) ]其中p=1/2(a+b+c)     

原创 codeforces 723E. One-Way Reform(歐拉回路||網絡流)

E. One-Way Reform time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp

原创 codeforces 719C. Efim and Strange Grade

C. Efim and Strange Grade time limit per test 1 second memory limit per test 256 megabytes input standard input

原创 LIS && LCS && LCIS

1、LIS:一個a序列,求它的最大上升子序列的最大長度 2、LCS:兩個序列a和b,求他們最大公共子序列的長度  3、LCIS:兩個序列a、b,求他們最大公共上升子序列長度 【求長度並輸出序列:CF10D. LCIS】 #inclu