Time of Update: 2018-12-03
tarjan縮點+樹的直徑https://www.byvoid.com/blog/scc-tarjan/ 講tarjian比較好http://blog.csdn.net/u010638776/article/details/9472605 借鑒了這裡 #include<iostream>#include<cstdio>#include<cstdio>#include<queue>#pragma comment(linker,
Time of Update: 2018-12-03
tarjan縮點題意:有n個牛,m個關係。並且如果a->b b->c 則a->c.先用tarjan把各個強連通分量縮成一個點,(這個點裡的奶牛互相仰慕)並且記錄下各個強連通分量裡點的個數。找出出度為0的強連通分量,若只有1個,則輸出該強連通分量裡點的個數。若找到多個出度為0的強連通分量,輸出0. //148K 16MS
Time of Update: 2018-12-03
tarjan演算法注意:如果是強連通圖的化輸出0 1通過tarjan演算法縮點。第一問輸出入度點=0的個數。第二問中添加的邊數是max(入度點=0的個數,出度點=0的個數)。 暫且當定理記下。#include<iostream>#include<cstdio>#include<cstring>using namespace std;#define maxm 21000#define maxn 220int n;int head[maxn],cnt;int v[
Time of Update: 2018-12-03
線段樹//31MS 340K c++#include<iostream>#include<cstdio>using namespace std;#define maxn 5010#define ls (rt<<1)#define rs (rt<<1|1)#define mid ((t[rt].l+t[rt].r)>>1)struct tree{int l,r;int sum;}t[maxn<<4];int num[maxn]
Time of Update: 2018-12-03
差分約束注意點是要建立一個超級原點 防止有多個分圖出現#include<queue>#include<iostream>#include<cstdio>using namespace std;#define INF 10000001#define esp 1int n,m;int head[2][30015],v[2][30015],next[2][30015];double w[2][30015];double dis[1005];int input[150
Time of Update: 2018-12-03
tarjan演算法最終添加完邊的圖,肯定可以分成兩個部X和Y,其中只有X到Y的邊沒有Y到X的邊,那麼要使得邊數儘可能的多,則X部肯定是一個完全圖,Y部也是,同時X部中每個點到Y部的每個點都有一條邊,假設X部有x個點,Y部有y個點,有x+y=n,同時邊數F=x*y+x*(x-1)+y*(y-1),整理得:F=N*N-N-x*y,當x+y為定值時,二者越接近,x*y越大,所以要使得邊數最多,那麼X部和Y部的點數的個數差距就要越大,所以首先對於給定的有向圖縮點,對於縮點後的每個點,如果它的出度或者入度
Time of Update: 2018-12-03
DescriptionYoung Andrew is playing yet another numbers game. Initially, he writes down an integerA. Then, he chooses some divisor d1 ofA, 1 < d1 < A, erases A and writes A1=A+ d1 instead. Then, he chooses some divisord2 of A1, 1 <
Time of Update: 2018-12-03
樹的直徑求出樹的直徑後分類討論。#include<iostream>#include<cstdio>#include<cstring>#include<queue>using namespace std;#define maxn 200005int head[maxn];int v[maxn],next[maxn],cnt;int n,m,r;void add(int x,int
Time of Update: 2018-12-03
找規律a(n)=(n+3)*2^(n-2) a(n+1) = 2*a(n) + 2^(n-1) a0=1 a1=21 2 5 12 #include<iostream>#include<cstdio>#include<cstring>using namespace std;#define mod 1000000007#define LL __int64LL Pow(LL n){ if(n==1) return 2;
Time of Update: 2018-12-03
Quantity Of The Stones Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)Total Submission(s) : 45 Accepted Submission(s) : 11Font: Times New Roman | Verdana | Georgia Font Size: ← →Problem Description xysDavidCN
Time of Update: 2018-12-03
http://blog.csdn.net/dyx404514/article/details/9474251上面的那個很好的解釋了。以11 5 3 為例 5 3 的最小公倍數151 2 3 4 5 6 7 8 9 10 11 12 13 14 150 1 2 3 4 0 1 2 3 4 0 1 2 3 4 放進a箱子 i%5的值以5為迴圈 0 1 2 0 1 2 0 1 2 0 1 2 0
Time of Update: 2018-12-03
模板1:改點求段http://acm.hdu.edu.cn/showproblem.php?pid=1166 hdu 1166 敵兵布陣#include<iostream>#include<cstdio>#include<cstring>using namespace std;int a[50004],n;char str[20];int lowbit(int i){return i&(-i);}int Sum(int i){int
Time of Update: 2018-12-03
--這個是截取字串的函數,在產生預存程序的時候調用了gocreate function [dbo].[f_split](@SourceSql varchar(max),@StrSeprate varchar(10)) returns @temp table(Rowvalue varchar(1000))as begin declare @i int set @SourceSql=rtrim(ltrim(@SourceSql)) set
Time of Update: 2018-12-03
樹狀數組。#include<iostream>#include<cstdio>#include<cstring>using namespace std;#define maxn 100006int a[maxn];int n=maxn;int lowbit(int i){return i&(-i);}int Sum(int i){int sum=0;while(i>=1){sum+=a[i];i-=lowbit(i);}return
Time of Update: 2018-12-03
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html;
Time of Update: 2018-12-03
樹狀數組#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define maxn 100006int a[maxn];int n=maxn;struct Note{int val,ord;}b[maxn];bool cmp(Note a,Note b){return a.val<b.val;}int
Time of Update: 2018-12-03
差分約束建圖spfa求的最長路徑 #include<iostream>#include<cstdio>#include<queue>#include<cstring>using namespace std;#define INF 100000int head[151000],v[151000],w[151000],next[151000];int dis[51000];bool vis[51000];int cnt,n,m;void
Time of Update: 2018-12-03
差分約束#include<iostream>#include<cstdio>#include<cstring>#include<queue>using namespace std;#define INF 10000001int n,m;int head[30015],v[30015],w[30015],next[30015];int vis[10015],dis[10015];int cnt;void add(int a,int b,int c){
Time of Update: 2018-12-03
查分約束 #include<iostream>#include<cstdio>#include<cstring>#include<queue>using namespace std;#define INF 1000001int head[30000],v[30000],w[30000],next[30000];int dis[2000],vis[2000],output[2000];int cnt,n,l,d;void add(int a,int
Time of Update: 2018-12-03
差分約束#include<cstdio>#include<iostream>#include<cstring>#include<queue>using namespace std;#define INF 10000001int n,m,cnt;int head[350001],v[350001],w[350001],next[350001];int dis[1005],vis[1005],output[1005];void add(int