虽然这个队,以后再也没有了,但是他的模板,是永垂不朽的!【误

  1. #include <ext/pb_ds/priority_queue.hpp>
  2. __gnu_pbds::priority_queue < int > Q;
  3. 优先队列,配对堆默认,从小到大!
  4. __gnu_pbds::priority_queue < int , greater < int > , pairing_heap_tag > Q;
  5. __gnu_pbds::priority_queue < int , greater < int > , pairing_heap_tag > :: point_iterator id[ maxn ];
  6. id[x] = Q.push( 5 ) ;
  7. Q.modify( id[x] , 6) ; //直接修改
  8. 支持join , push , pop操作
  9. #include <ext/pb_ds/assoc_container.hpp>
  10. using namespace __gnu_pbds;
  11. tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbt;
  12. tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> :: iterator it ;
  13. find_by_order(size_type order)
  14. 找第order+1小的元素的迭代器
  15. order_of_key(int val)
  16. 问有多少个比val
  17. #include <ext/pb_ds/assoc_container.hpp>
  18. #include <ext/pb_ds/hash_policy.hpp>
  19. __gnu_pbds::gp_hash_table < key , value > hs;
  20. 哈希
  21. 支持[]和find操作
  22. 三角形:
  23. 1. 半周长 P=(a+b+c)/2
  24. 2. 面积 S=aHa/2=absin(C)/2=sqrt(P(P-a)(P-b)(P-c))
  25. 3. 中线 Ma=sqrt(2(b^2+c^2)-a^2)/2=sqrt(b^2+c^2+2bccos(A))/2
  26. 4. 角平分线 Ta=sqrt(bc((b+c)^2-a^2))/(b+c)=2bccos(A/2)/(b+c)
  27. 5. 高线 Ha=bsin(C)=csin(B)=sqrt(b^2-((a^2+b^2-c^2)/(2a))^2)
  28. 6. 内切圆半径 r=S/P=asin(B/2)sin(C/2)/sin((B+C)/2)
  29. =4Rsin(A/2)sin(B/2)sin(C/2)=sqrt((P-a)(P-b)(P-c)/P)
  30. =Ptan(A/2)tan(B/2)tan(C/2)
  31. 7. 外接圆半径 R=abc/(4S)=a/(2sin(A))=b/(2sin(B))=c/(2sin(C))
  32. 四边形:
  33. D1,D2为对角线,M对角线中点连线,A为对角线夹角
  34. 1. a^2+b^2+c^2+d^2=D1^2+D2^2+4M^2
  35. 2. S=D1D2sin(A)/2
  36. (以下对圆的内接四边形)
  37. 3. ac+bd=D1D2
  38. 4. S=sqrt((P-a)(P-b)(P-c)(P-d)),P为半周长
  39. n边形:
  40. R为外接圆半径,r为内切圆半径
  41. 1. 中心角 A=2PI/n
  42. 2. 内角 C=(n-2)PI/n
  43. 3. 边长 a=2sqrt(R^2-r^2)=2Rsin(A/2)=2rtan(A/2)
  44. 4. 面积 S=nar/2=nr^2tan(A/2)=nR^2sin(A)/2=na^2/(4tan(A/2))
  45. 圆:
  46. 1. 弧长 l=rA
  47. 2. 弦长 a=2sqrt(2hr-h^2)=2rsin(A/2)
  48. 3. 弓形高 h=r-sqrt(r^2-a^2/4)=r(1-cos(A/2))=atan(A/4)/2
  49. 4. 扇形面积 S1=rl/2=r^2A/2
  50. 5. 弓形面积 S2=(rl-a(r-h))/2=r^2(A-sin(A))/2
  51. 棱柱:
  52. 1. 体积 V=Ah,A为底面积,h为高
  53. 2. 侧面积 S=lp,l为棱长,p为直截面周长
  54. 3. 全面积 T=S+2A
  55. 棱锥:
  56. 1. 体积 V=Ah/3,A为底面积,h为高
  57. (以下对正棱锥)
  58. 2. 侧面积 S=lp/2,l为斜高,p为底面周长
  59. 3. 全面积 T=S+A
  60. 棱台:
  61. 1. 体积 V=(A1+A2+sqrt(A1A2))h/3,A1.A2为上下底面积,h为高
  62. (以下为正棱台)
  63. 2. 侧面积 S=(p1+p2)l/2,p1.p2为上下底面周长,l为斜高
  64. 3. 全面积 T=S+A1+A2
  65. 圆柱:
  66. 1. 侧面积 S=2PIrh
  67. 2. 全面积 T=2PIr(h+r)
  68. 3. 体积 V=PIr^2h
  69. 圆锥:
  70. 1. 母线 l=sqrt(h^2+r^2)
  71. 2. 侧面积 S=PIrl
  72. 3. 全面积 T=PIr(l+r)
  73. 4. 体积 V=PIr^2h/3
  74. 圆台:
  75. 1. 母线 l=sqrt(h^2+(r1-r2)^2)
  76. 2. 侧面积 S=PI(r1+r2)l
  77. 3. 全面积 T=PIr1(l+r1)+PIr2(l+r2)
  78. 4. 体积 V=PI(r1^2+r2^2+r1r2)h/3
  79. 球:
  80. 1. 全面积 T=4PIr^2
  81. 2. 体积 V=4PIr^3/3
  82. 球台:
  83. 1. 侧面积 S=2PIrh
  84. 2. 全面积 T=PI(2rh+r1^2+r2^2)
  85. 3. 体积 V=PIh(3(r1^2+r2^2)+h^2)/6
  86. 球扇形:
  87. 1. 全面积 T=PIr(2h+r0),h为球冠高,r0为球冠底面半径
  88. 2. 体积 V=2PIr^2h/3
  89. 从左边的未匹配点开始进行BFS,对于左边的点,依次检查所有向连的点并加入BFS(判断是否加过),右边的点只能走匹配边,然后对访问到的点进行标记,取左边没被标记的,右边标记了的
  90. 如果一个图是二分图,那么它的最大独立集就是多项式时间可以解决的问题了 |最大独立集| = |V|-|最大匹配数|
  91. 二分图的最大团 = 补图的最大独立集
  92. 先做一次最大匹配 然后对于已经匹配的点 如果他存在与之相连 但是不是被匹配的点 那么他总是在最小覆盖集里面
  93. 1.给一张图,问有多少条边肯定在 MST 上?
  94. 对所有边排序,每次扫出权值相同的边,然后跑tarjan_dcc(求割边),有多少条割边,表示对答案的贡献就是多少,之后将这些边的两边点进行缩点(并查集维护)
  95. for(int i = 0 ; i < m ; ++ i)
  96. {
  97. int base = e[i].w;
  98. for(int j = i + 1 ; j < m ; ++ j){
  99. //扫描相同权值的边
  100. //进行tarjan_dcc算法
  101. //合并
  102. }
  103. }
  104. 2.给一张图,问有多少条边可能在 MST 上?
  105. 对所有边排序,每次新加入一条边之后,向后扫描所有相同权值的边,如果有边也可以合并两端,则打上标记
  106. for(int i = 0 ; i < m ; ++ i)
  107. {
  108. if (find_set(e[i].u) == find_set(e[i].v) ) continue;
  109. int a1 = find_set(e[i].u) ,a2 = find_set(e[i].v);
  110. if (a1 > a2)
  111. swap(a1,a2);
  112. for(int j = i + 1 ; j < m ; ++ j)
  113. {
  114. if (e[j].w != e[i].w ) break;
  115. int b1 = find_set(e[j].u) , b2 =find_set(e[j].v);
  116. if (b1 > b2)
  117. swap(b1,b2);
  118. if ( a1 == b1 && a2 == b2)
  119. flag[j] = 1;
  120. }
  121. union_set(e[i].u ,e[i].v);
  122. flag[i] = 1;
  123. }
  124. 3.可以一次dfsn^2的时间预处理出树上任意两点的某个属性,用dp
  125. dfs(int u)
  126. {
  127. vis[u] = 1;
  128. for(int i = head[u] ; ~i ; i =e[i].nxt)
  129. {
  130. int v = e[i].v;
  131. for(int j = 1 ; j <= n ; ++ j)
  132. if(vis[j])
  133. 更新dp
  134. }
  135. }
  136. KM算法
  137. const int maxn = 300 ;
  138. const int inf = 1e9;
  139. int mat[maxn + 1][maxn + 1] , N ;
  140. int lx[maxn + 1];
  141. int ly[maxn + 1];
  142. int slack[maxn + 1];
  143. int S[maxn + 1];
  144. int T[maxn + 1];
  145. int lft[maxn + 1];
  146. bool dfs( int x ){
  147. S[x] = 1;
  148. for(int i = 1 ; i <= N ; ++ i)
  149. if( !T[i] ){
  150. int gap = lx[x] + ly[i] - mat[x][i];
  151. if( gap == 0 ){
  152. T[i] = 1;
  153. if( lft[i] == 0 || dfs( lft[i] ) ){
  154. lft[i] = x;
  155. return true;
  156. }
  157. }else slack[i] = min( slack[i] , gap );
  158. }
  159. return false;
  160. }
  161. int solve(){
  162. for(int i = 1 ; i <= N ; ++ i){
  163. lx[i] = ly[i] = lft[i] = 0;
  164. for(int j = 1 ; j <= N ; ++ j) lx[i] = max( lx[i] , mat[i][j] );
  165. }
  166. for(int i = 1 ; i <= N ; ++ i){
  167. while( 1 ){
  168. for(int j = 1 ; j <= N ; ++ j) slack[j] = inf , S[j] = T[j] = 0;
  169. if( dfs( i ) ) break;
  170. int d = inf;
  171. for(int j = 1 ; j <= N ; ++ j) if( !T[j] ) d = min( d , slack[j] );
  172. for(int j = 1 ; j <= N ; ++ j){
  173. if( S[j] ) lx[j] -= d;
  174. if( T[j] ) ly[j] += d;
  175. }
  176. }
  177. }
  178. int res = 0;
  179. for(int i = 1 ; i <= N ; ++ i) res += lx[i] + ly[i];
  180. return res;
  181. }
  182. Tarjan_bcc
  183. int tarjan_dfs(int u,int fa)
  184. {
  185. dfn[u] = low[u] = ++T;
  186. for(int i = head[u] ; ~i ; i = e[i].nxt)
  187. {
  188. int v = e[i].v;
  189. if(v == fa) continue;
  190. if(!dfn[v])
  191. {
  192. s.push(make_pair(u,v));
  193. int lowv = tarjan_dfs(v,u);
  194. low[u] = min(low[u],lowv);
  195. if(lowv >= dfn[u])
  196. {
  197. bcc_cnt++;bcc[bcc_cnt].clear();
  198. while(1)
  199. {
  200. dl ss = s.top();s.pop();
  201. int x = ss.first , y = ss.second;
  202. if(belong[x] != bcc_cnt)
  203. {
  204. bcc[bcc_cnt].push_back(x);
  205. belong[x] = bcc_cnt;
  206. }
  207. if(belong[y] != bcc_cnt)
  208. {
  209. bcc[bcc_cnt].push_back(y);
  210. belong[y] = bcc_cnt;
  211. }
  212. if(x==u&&y==v) break;
  213. }
  214. }
  215. }
  216. else if(dfn[v] < dfn[u])
  217. {
  218. s.push(make_pair(u,v));
  219. low[u] = min(low[u] , dfn[v]);
  220. }
  221. }
  222. return low[u];
  223. }
  224. 辛普森积分
  225. double F(double x){ return exp(-x*x/2); }
  226. double simpson( double a , double b ){
  227. double c = a + ( b - a ) / 2;
  228. return (F(a) + 4*F(c) + F(b))*(b-a) / 6;
  229. }
  230. double asr( double a , double b , double eps , double A){
  231. double c = a + ( b - a ) / 2;
  232. double L = simpson( a , c ) , R = simpson( c , b );
  233. if(fabs(L+R-A) <= 15*eps) return L + R + (L+R-A)/15.0;
  234. return asr( a , c , eps / 2 , L ) + asr( c , b , eps / 2 , R);
  235. }
  236. double asr( double a , double b , double eps ){
  237. return asr( a , b , eps , simpson( a , b ) );
  238. }
  239. XorK的方案数
  240. int n , p[maxn] , dp[maxn][2] , dp2[maxn][2] , target ;
  241. int solve( int target ){
  242. int rs = 0 , bit ;
  243. for(bit = 30 ; bit >= 0 ; -- bit){
  244. memset( dp , 0 , sizeof( dp ) );
  245. memset( dp2 , 0 , sizeof( dp2 ) );
  246. dp[0][0] = dp2[n + 1][0] = 1;
  247. for(int i = 0 ; i < n ; ++ i) for(int f = 0 ; f < 2 ; ++ f) if( dp[i][f] ){
  248. if( p[i + 1] >> bit & 1 ){
  249. up( dp[i + 1][f ^ 1] , mul( dp[i][f] , (p[i + 1]&((1<<bit)-1))+1 ));
  250. up( dp[i + 1][f] , mul( dp[i][f] , 1 << bit ) );
  251. }else up( dp[i + 1][f] , mul( dp[i][f] , (p[i + 1]&((1<<bit)-1))+1 ));
  252. }
  253. for(int i = n + 1 ; i > 1 ; -- i) for(int f = 0 ; f < 2 ; ++ f) if( dp2[i][f] ){
  254. if( p[i - 1] >> bit & 1 ) up( dp2[i - 1][f ^ 1] , mul( dp2[i][f] , (p[i - 1]&((1<<bit)-1))+1 ));
  255. else up( dp2[i - 1][f] , mul( dp2[i][f] , (p[i - 1]&((1<<bit)-1))+1 ));
  256. }
  257. int pre = 0 ;
  258. for(int i = n; i >= 1 ; -- i){
  259. if( p[i] >> bit & 1 ) for(int j = 0 ; j < 2 ; ++ j) up( rs , mul( dp[i - 1][j] , dp2[i + 1][ (target >> bit & 1) ^ j ] ) );
  260. pre ^= ( p[i] >> bit & 1 );
  261. }
  262. if( pre != ( target >> bit & 1 ) ) break;
  263. }
  264. return rs + (bit == -1);
  265. }
  266. 1e9内素数和
  267. long long dp[maxn][105];
  268. int vis[maxn * 100] , tot , prime[maxn * 100] ;
  269. int cal(long long x){
  270. int l = 0 , r = tot - 1;
  271. while(l <= r){
  272. int mid = l + ( (r-l) >> 1);
  273. if( 1LL * (long long)prime[mid] * prime[mid] <= x) l = mid + 1;
  274. else r = mid - 1;
  275. }
  276. return prime[l-1];
  277. }
  278. long long dfs(int x , int y){
  279. if(y <= 1) return ( 1LL * (x + 2) * (x - 1) ) >> 1LL; //边界条件
  280. int flag = ( x <= 1e4 && y <= 1e2);
  281. if( 1LL * y * y > x) return dfs( x , cal(x)); //find
  282. if( vis[y] ) return dfs( x , prime[upper_bound(prime , prime + tot , y ) - prime - 1] );
  283. if(flag && ~dp[x][y]) return dp[x][y];
  284. long long ans = 0;
  285. ans = dfs( x , y - 1 ) - 1LL * y * ( dfs(x / y , y - 1 ) - dfs( y - 1 , cal( y - 1 )) );
  286. if(flag) dp[x][y] = ans;
  287. return ans;
  288. }
  289. void init(){
  290. for(int i = 2 ; i <= 1e6 ; ++ i)
  291. if(!vis[i]){
  292. prime[tot++] = i;
  293. for(int j = i * 2 ; j <= 1e6 ; j += i) vis[j] = 1;
  294. }
  295. }
  296. 快速求第一类斯特林数
  297. int seq[60][maxn << 1] , ptr = 0;
  298. long long B[maxn << 1] , C[maxn << 1];
  299. int DFS( int l , int r ){
  300. if( l == r ){
  301. int id = ptr ++ ;
  302. seq[id][1] = l ;
  303. seq[id][0] = 1 ;
  304. return id;
  305. }else{
  306. int mid = l + r >> 1;
  307. int lid = DFS( l , mid );
  308. int rid = DFS( mid + 1 , r );
  309. ptr -= 2;
  310. int newid = ptr ++ ;
  311. int len = 1;
  312. while( len <= r - l + 1 ) len <<= 1;
  313. for(int i = 0 ; i < len ; ++ i) B[i] = seq[lid][i] , C[i] = seq[rid][i] , seq[lid][i] = seq[rid][i] = 0;
  314. NTT( B , len , 1 );
  315. NTT( C , len , 1 );
  316. for(int i = 0 ; i < len ; ++ i) B[i] = B[i] * C[i] % Mod;
  317. NTT( B , len , -1 );
  318. for(int i = 0 ; i < len ; ++ i) seq[newid][i] = B[i];
  319. return newid;
  320. }
  321. }
  322. int id = DFS( 0 , N - 1 );
  323. for(int i = N ; i >= 0 ; -- i){
  324. printf( "f[%d] is %d \n" , N - i , seq[id][i] );
  325. }
  326. FFT
  327. const double PI = acos(-1.0);
  328. //复数结构体
  329. struct Complex
  330. {
  331. double r,i;
  332. Complex(double _r = 0.0,double _i = 0.0)
  333. {
  334. r = _r; i = _i;
  335. }
  336. Complex operator +(const Complex &b)
  337. {
  338. return Complex(r+b.r,i+b.i);
  339. }
  340. Complex operator -(const Complex &b)
  341. {
  342. return Complex(r-b.r,i-b.i);
  343. }
  344. Complex operator *(const Complex &b)
  345. {
  346. return Complex(r*b.r-i*b.i,r*b.i+i*b.r);
  347. }
  348. };
  349. /*
  350. * 进行FFT和IFFT前的反转变换。
  351. * 位置i和 (i二进制反转后位置)互换
  352. * len必须去2的幂
  353. */
  354. void change(Complex y[],int len)
  355. {
  356. int i,j,k;
  357. for(i = 1, j = len/2;i < len-1; i++)
  358. {
  359. if(i < j)swap(y[i],y[j]);
  360. //交换互为小标反转的元素,i<j保证交换一次
  361. //i做正常的+1,j左反转类型的+1,始终保持i和j是反转的
  362. k = len/2;
  363. while( j >= k)
  364. {
  365. j -= k;
  366. k /= 2;
  367. }
  368. if(j < k) j += k;
  369. }
  370. }
  371. /*
  372. * 做FFT
  373. * len必须为2^k形式,
  374. * on==1时是DFT,on==-1时是IDFT
  375. */
  376. void fft(Complex y[],int len,int on)
  377. {
  378. change(y,len);
  379. for(int h = 2; h <= len; h <<= 1)
  380. {
  381. Complex wn(cos(-on*2*PI/h),sin(-on*2*PI/h));
  382. for(int j = 0;j < len;j+=h)
  383. {
  384. Complex w(1,0);
  385. for(int k = j;k < j+h/2;k++)
  386. {
  387. Complex u = y[k];
  388. Complex t = w*y[k+h/2];
  389. y[k] = u+t;
  390. y[k+h/2] = u-t;
  391. w = w*wn;
  392. }
  393. }
  394. }
  395. if(on == -1)
  396. for(int i = 0;i < len;i++)
  397. y[i].r /= len;
  398. }
  399. FWT
  400. #include <bits/stdc++.h>
  401. using namespace std;
  402. const int N = 1 << 20;
  403. int a[N];
  404. void tfand(int a[], int n) {
  405. if(n == 1) return;
  406. int x = n >> 1;
  407. tfand(a, x); tfand(a + x, x);
  408. for(int i = 0; i < x; ++ i)
  409. a[i] += a[i + x];
  410. }
  411. void utfand(long long a[], int n) {
  412. if(n == 1) return;
  413. int x = n >> 1;
  414. for(int i = 0; i < x; ++ i)
  415. a[i] -= a[i + x];
  416. utfand(a, x); utfand(a + x, x);
  417. }
  418. void tfor(int a[], int n) {
  419. if(n == 1) return;
  420. int x = n >> 1;
  421. tfor(a, x); tfor(a + x, x);
  422. for(int i = 0; i < x; ++ i)
  423. a[i + x] += a[i];
  424. }
  425. void utfor(long long a[], int n) {
  426. if(n == 1) return;
  427. int x = n >> 1;
  428. for(int i = 0; i < x; ++ i)
  429. a[i + x] -= a[i];
  430. utfor(a, x); utfor(a + x, x);
  431. }
  432. long long t[N];
  433. void utfxor(long long a[], int n) {
  434. if(n == 1) return;
  435. int x = n >> 1;
  436. for(int i = 0; i < x; ++ i) {
  437. t[i] = (a[i] + a[i + x]) >> 1;
  438. t[i + x] = (a[i + x] - a[i]) >> 1;
  439. }
  440. memcpy(a, t, n * sizeof(long long));
  441. utfxor(a, x); utfxor(a + x, x);
  442. }
  443. int tmp[N];
  444. void tfxor(int a[], int n) {
  445. if(n == 1) return;
  446. int x = n >> 1;
  447. tfxor(a, x); tfxor(a + x, x);
  448. for(int i = 0; i < x; ++ i) {
  449. tmp[i] = a[i] - a[i + x];
  450. tmp[i + x] = a[i] + a[i + x];
  451. }
  452. memcpy(a, tmp, n * sizeof(int));
  453. }
  454. long long b[N];
  455. int c[N];
  456. NTT
  457. typedef long long ll;
  458. const ll Mod=998244353; // 模数
  459. const ll SpMul=3; // 原根
  460. ll qpow(ll a,ll k)
  461. {
  462. ll res=1LL;
  463. while(k>0)
  464. {
  465. if(k&1)res=res*a%Mod;
  466. a=a*a%Mod;
  467. k>>=1;
  468. }
  469. return res;
  470. }
  471. void Change(ll y[],int len)
  472. {
  473. for(int i=1,j=len/2;i<len-1;i++)
  474. {
  475. if(i<j)swap(y[i],y[j]);
  476. int k=len/2;
  477. while(j>=k)
  478. {
  479. j-=k;
  480. k/=2;
  481. }
  482. if(j<k)j+=k;
  483. }
  484. }
  485. void NTT(ll y[],int len,int on)
  486. {
  487. Change(y,len);
  488. for(int h=2;h<=len;h<<=1)
  489. {
  490. ll wn=qpow(SpMul,(Mod-1)/h);
  491. if(on==-1)wn=qpow(wn,Mod-2);
  492. for(int j=0;j<len;j+=h)
  493. {
  494. ll w=1LL;
  495. for(int k=j;k<j+h/2;k++)
  496. {
  497. ll u=y[k];
  498. ll t=w*y[k+h/2]%Mod;
  499. y[k]=(u+t)%Mod;
  500. y[k+h/2]=(u-t+Mod)%Mod;
  501. w=w*wn%Mod;
  502. }
  503. }
  504. }
  505. if(on==-1)
  506. {
  507. ll t=qpow(len,Mod-2);
  508. for(int i=0;i<len;i++)
  509. y[i]=y[i]*t%Mod;
  510. }
  511. }
  512. CRTEx_GCD 求逆
  513. X / y % p = X % (y*p) / y
  514. void extend_gcd(long long a , long long b , long long& d , long long & x , long long &y )
  515. {
  516. if (!b)
  517. {
  518. d = a;
  519. x = 1;
  520. y = 0;
  521. }
  522. else
  523. {
  524. extend_gcd(b,a%b,d,y,x);
  525. y -= x*(a/b);
  526. }
  527. }
  528. long long inv(long long a,long long n)
  529. {
  530. long long d , x , y;
  531. extend_gcd(a,n,d,x,y);
  532. return d==1? (x+n) % n : -1;
  533. }
  534. // n个方程,x=a[i] (mod m[i]) ( 0 <= i < n)
  535. long long CRT(int n ,long long * a , long long * m)
  536. {
  537. long long M = 1 , d , y , x = 0;
  538. for(int i = 0 ; i < n ; ++ i) M*=m[i];
  539. for(int i = 0 ; i < n ; ++ i)
  540. {
  541. long long w = M / m[i];
  542. extend_gcd(m[i],w,d,d,y);
  543. x = (x + y*w*a[i])%M;
  544. }
  545. return (x+M)%M;
  546. }
  547. 高斯消元(高精度)
  548. const int MatrixSize = 50;
  549. const double eps = 1e-8;
  550. typedef double Matrix[MatrixSize][MatrixSize];
  551. void Gauss(Matrix A, int n)
  552. {
  553. int i, j, k, r;
  554. for(i = 0; i < n; ++ i)
  555. {
  556. r = i;
  557. for(j = i+1; j < n; ++ j)
  558. if (fabs(A[j][i]) > fabs(A[r][i])) r = j;
  559. if(fabs(A[r][i]) < eps) continue;
  560. if(r != i) for(j = 0; j <= n; j++) swap(A[r][j], A[i][j]);
  561. for(k = 0; k < n; k++) if(k != i)
  562. for(j = n; j >= i; j--) A[k][j] -= A[k][i]/A[i][i] * A[i][j];
  563. }
  564. for(i = 0 ; i < n ; ++ i)
  565. {
  566. if(fabs(A[i][n]) < eps) A[i][n] = 0;
  567. else A[i][n] /= A[i][i];
  568. }
  569. }
  570. 算原根
  571. #include <iostream>
  572. #include <cstdlib>
  573. #include <cstring>
  574. #include <cstdio>
  575. using namespace std;
  576. int P;
  577. const int NUM = 32170;
  578. int prime[NUM/4];
  579. bool f[NUM];
  580. int pNum = 0;
  581. void getPrime()//线性筛选素数
  582. {
  583. for (int i = 2; i < NUM; ++ i)
  584. {
  585. if (!f[i])
  586. {
  587. f[i] = 1;
  588. prime[pNum++] = i;
  589. }
  590. for (int j = 0; j < pNum && i*prime[j] < NUM; ++ j)
  591. {
  592. f[i*prime[j]] = 1;
  593. if (i%prime[j] == 0)
  594. {
  595. break;
  596. }
  597. }
  598. }
  599. }
  600. __int64 getProduct(int a,int b,int P)//快速求次幂mod
  601. {
  602. __int64 ans = 1;
  603. __int64 tmp = a;
  604. while (b)
  605. {
  606. if (b&1)
  607. {
  608. ans = ans*tmp%P;
  609. }
  610. tmp = tmp*tmp%P;
  611. b>>=1;
  612. }
  613. return ans;
  614. }
  615. bool judge(int num)//求num的所有的质因子
  616. {
  617. int elem[1000];
  618. int elemNum = 0;
  619. int k = P - 1;
  620. for (int i = 0; i < pNum; ++ i)
  621. {
  622. bool flag = false;
  623. while (!(k%prime[i]))
  624. {
  625. flag = true;
  626. k /= prime[i];
  627. }
  628. if (flag)
  629. {
  630. elem[elemNum ++] = prime[i];
  631. }
  632. if (k==1)
  633. {
  634. break;
  635. }
  636. if (k/prime[i]<prime[i])
  637. {
  638. elem[elemNum ++] = prime[i];
  639. break;
  640. }
  641. }
  642. bool flag = true;
  643. for (int i = 0; i < elemNum; ++ i)
  644. {
  645. if (getProduct(num,(P-1)/elem[i],P) == 1)
  646. {
  647. flag = false;
  648. break;
  649. }
  650. }
  651. return flag;
  652. }
  653. int main()
  654. {
  655. getPrime();
  656. while (cin >> P)
  657. {
  658. for (int i = 2; i <= P ;++i)
  659. {
  660. if (judge(i))
  661. {
  662. cout << i<< endl;
  663. break;
  664. }
  665. }
  666. }
  667. return 0;
  668. }
  669. 降幂公式
  670. A^x = A^(x % Phi(C) + Phi(C)) (mod C),其中xPhi(C) 这个降幂公式适用于C不是素数的情况
  671. A ^ X % C = A ^ ( X % ( C - 1 ) ) 这个降幂公式只适用于C是素数的情况
  672. 回文自动机
  673. struct Palindromic_Auto{
  674. const static int maxn = 2e5 + 15;
  675. const static int lettersz = 26;
  676. int link[maxn] , len[maxn] , last , tot , nxt[maxn][lettersz] , s[maxn] , n ;
  677. void init( int id , int l ){ memset( nxt[id] , 0 , sizeof( nxt[id] ) ); len[id] = l; }
  678. void init(){ n = last = 0 , s[0] = -1 , link[0] = tot = 1; init( 0 , 0 ) , init( 1 , -1 ); }
  679. int gethash( char c ){ return c -'a' ;}
  680. int extend( char c ){
  681. s[ ++ n ] = gethash( c );
  682. int cur = last ;
  683. while( s[n - len[cur] - 1] != s[n] ) cur = link[cur];
  684. if( !nxt[cur][s[n]] ){
  685. int id = ++ tot , t = link[cur] ; init( id , len[cur] + 2 );
  686. while( s[n - len[t] - 1] != s[n] ) t = link[t];
  687. link[id] = nxt[t][s[n]] , nxt[cur][s[n]] = id;
  688. }
  689. last = nxt[cur][s[n]];
  690. return len[last];
  691. }
  692. }pa_auto;
  693. 后缀自动机
  694. struct Suffix_Auto{
  695. const static int maxn = ( 1e5 + 50 ) * 2;
  696. const static int lettersz = 26;
  697. int tot , last , link[maxn] , nxt[maxn][lettersz] , len[maxn];
  698. int gethash( char c ){ return c -'a' ;}
  699. void init( int idx ){ link[idx] = len[idx] = 0 , memset( nxt[idx] , 0 , sizeof( nxt[idx] ) ); }
  700. void init(){ memset(nxt[0],0,sizeof(nxt[0])) ; last = tot = len[0] = 0 , link[0] = -1 ; }
  701. void extend( char c ){
  702. int cur = ++ tot , p , q , id = gethash( c ) ;
  703. init( cur ) ;
  704. len[cur] = len[last] + 1;
  705. for( p = last ; ~p && !nxt[p][id] ; p = link[p] ) nxt[p][id] = cur;
  706. if( ~p ){
  707. q = nxt[p][id];
  708. if( len[p] + 1 == len[q] ) link[cur] = q;
  709. else{
  710. // Pay attention to init for clone , such as cnt array
  711. int clone = ++ tot ;
  712. len[clone] = len[p] + 1 , memcpy( nxt[clone] , nxt[q] , sizeof(int)*lettersz ) , link[clone] = link[q];
  713. for( ; ~p && nxt[p][id] == q ; p = link[p] ) nxt[p][id] = clone;
  714. link[q] = link[cur] = clone;
  715. }
  716. }
  717. last = cur;
  718. }
  719. }Sam;
  720. 后缀数组
  721. struct SuffixArray{
  722. const static int maxn = 1e5 + 50;
  723. int sa[maxn],c[maxn],sq[maxn],sw[maxn],rank[maxn],height[maxn];
  724. void Build(int *s,int n,int m){
  725. ++ n;
  726. int * x = sq , *y = sw , p = 1 ;
  727. for(int i = 0 ; i < m ; ++ i) c[i] = 0;
  728. for(int i = 0 ; i < n ; ++ i) c[x[i]=s[i]]++;
  729. for(int i = 1 ; i < m ; ++ i) c[i] += c[i - 1];
  730. for(int i = n - 1 ; i >= 0 ; -- i) sa[--c[x[i]]] = i;
  731. for(int k = 1 ; p < n ; k <<= 1){
  732. p = 0;
  733. for(int i = n - k ; i < n ; ++ i) y[p ++] = i;
  734. for(int i = 0 ; i < n ; ++ i) if( sa[i] >= k ) y[p ++] = sa[i] - k;
  735. for(int i = 0 ; i < m ; ++ i) c[i] = 0;
  736. for(int i = 0 ; i < n ; ++ i) c[x[y[i]]]++;
  737. for(int i = 1 ; i < m ; ++ i) c[i] += c[i-1];
  738. for(int i = n - 1 ; i >= 0 ; -- i) sa[--c[x[y[i]]]]=y[i];
  739. swap( x , y ) ; p = 1 , x[sa[0]] = 0;
  740. for(int i = 1 ; i < n ; ++ i) x[sa[i]] = y[sa[i - 1]] == y[sa[i]] && y[sa[i - 1] + k] == y[sa[i] + k] ? p - 1 : p++;
  741. m = p;
  742. }
  743. -- n;
  744. for(int i = 0 ; i < n ; ++ i) sa[i] = sa[i + 1] , rank[sa[i]] = i;
  745. for(int i = 0 , k = 0 ; i < n ; ++ i ){
  746. if( !rank[i] ) continue;
  747. int j = sa[rank[i] - 1];
  748. if( k ) -- k;
  749. while( s[i + k] == s[j + k] ) ++ k;
  750. height[rank[i]] = k;
  751. }
  752. }
  753. }Sa;
  754. 马拉车
  755. void manacher(char s[],int l)
  756. {
  757. int i,j,k,ans=0;
  758. for(i=1;i<=l;++i)str[i<<1]=s[i],str[(i<<1)+1]='#';
  759. str[1]='#';str[l*2+1]='#';str[0]='&';str[l*2+2]='$';
  760. l=l*2+1;j=0;
  761. for(i=1;i<=l;)
  762. {
  763. while(str[i-j-1]==str[i+j+1])++j;
  764. p[i]=j;if(j>ans)ans=j;
  765. for(k=1;k<=j&&p[i]-k!=p[i-k];++k)p[i+k]=min(p[i-k],p[i]-k);
  766. i+=k;j=max(j-k,0);
  767. }
  768. }
  769. LCT 动态树
  770. Push是往下传,update是往上传
  771. const int MAXN = 200500;struct Node {
  772. Node *ch[2], *p; int size, value;
  773. bool rev;
  774. Node(int t = 0);
  775. inline bool dir(void) {return p->ch[1] == this;}
  776. inline void SetC(Node *x, bool d) {
  777. ch[d] = x; x->p = this;
  778. }
  779. inline void Rev(void) {
  780. swap(ch[0], ch[1]); rev ^= 1;
  781. }
  782. inline void Push(void) {
  783. if (rev) {
  784. ch[0]->Rev();
  785. ch[1]->Rev();
  786. rev = 0;
  787. }
  788. }
  789. inline void Update(void) {
  790. size = ch[0]->size + ch[1]->size + 1;
  791. }
  792. }Tnull, *null = &Tnull, *fim[MAXN];// 要记得额外更新null的信息
  793. Node::Node(int _value){ch[0] = ch[1] = p = null; rev = 0;}
  794. inline bool isRoot(Node *x) {return x->p == null || (x != x->p->ch[0] && x != x->p->ch[1]);}
  795. inline void rotate(Node *x) {
  796. Node *p = x->p; bool d = x->dir();
  797. p->Push(); x->Push();
  798. if (!isRoot(p)) p->p->SetC(x, p->dir()); else x->p = p->p;
  799. p->SetC(x->ch[!d], d);
  800. x->SetC(p, !d);
  801. p->Update();
  802. }
  803. inline void splay(Node *x) {
  804. x->Push();
  805. while (!isRoot(x)) {
  806. if (isRoot(x->p)) rotate(x);
  807. else {
  808. if (x->dir() == x->p->dir()) {rotate(x->p); rotate(x);}
  809. else {rotate(x); rotate(x);}
  810. }
  811. }
  812. x->Update();
  813. }
  814. inline Node* Access(Node *x) {
  815. Node *t = x, *q = null;
  816. for (; x != null; x = x->p) {
  817. splay(x); x->ch[1] = q; q = x;
  818. }
  819. splay(t); //info will be updated in the splay;
  820. return q;
  821. }
  822. inline void Evert(Node *x) {
  823. Access(x); x->Rev();
  824. }
  825. inline void link(Node *x, Node *y) {
  826. Evert(x); x->p = y;
  827. }
  828. inline Node* getRoot(Node *x) {
  829. Node *tmp = x;
  830. Access(x);
  831. while (tmp->Push(), tmp->ch[0] != null) tmp = tmp->ch[0];
  832. splay(tmp);
  833. return tmp;
  834. }// 一定要确定x和y之间有边
  835. inline void cut(Node *x, Node *y) {
  836. Access(x); splay(y);
  837. if (y->p != x) swap(x, y);
  838. Access(x); splay(y);
  839. y->p = null;
  840. }
  841. inline Node* getPath(Node *x, Node *y) {
  842. Evert(x); Access(y);
  843. return y;
  844. }
  845. inline void clear(void) {
  846. null->rev = 0; null->size = 0; null->value = 0;
  847. }int a[maxn];int main()
  848. {
  849. clear();
  850. int n=read();
  851. for(int i=0;i<=n+1;i++)
  852. fim[i] = new Node();
  853. for(int i=1;i<=n;i++)
  854. a[i]=read();
  855. for(int i=1;i<=n;i++)
  856. {
  857. int p = i+a[i];
  858. if(p>n)p=n+1;
  859. link(fim[i],fim[p]);
  860. }
  861. int m = read();
  862. while(m--)
  863. {
  864. int op = read();
  865. if(op == 1)
  866. {
  867. int x = read();
  868. x++;
  869. Access(fim[x]);
  870. splay(fim[x]);
  871. printf("%d\n",fim[x]->size - 1);
  872. }
  873. else
  874. {
  875. int x=read(),y=read();
  876. x++;
  877. int p = x+a[x];
  878. if(p>n)p=n+1;
  879. cut(fim[x],fim[p]);
  880. a[x]=y;
  881. p = x+a[x];
  882. if(p>n)p=n+1;
  883. link(fim[x],fim[p]);
  884. }
  885. }
  886. }
  887. Splay
  888. struct SplayTree{
  889. const static int maxn = 2e5 + 15;
  890. int ch[maxn][2] , s[maxn] , tot , root , fa[maxn];
  891. long long sum[maxn] , lzy[maxn] ;
  892. int index[maxn] , key[maxn];
  893. void init( int x , int id = 0 , int val = 0 , int par = 0 ){
  894. ch[x][0]=ch[x][1]=0 , fa[x]= par , key[x] = val , index[x] = id , s[x] = 1;
  895. }
  896. void init(){
  897. init( 0 , 0 , 0 , 0 ); s[0] = 0;
  898. tot = root = 0 ;
  899. }
  900. inline void up(int x){
  901. s[x] = s[ch[x][0]] + s[ch[x][1]] + 1;
  902. sum[x] = key[x];
  903. if( ch[x][0] ) sum[x] += sum[ch[x][0]];
  904. if( ch[x][1] ) sum[x] += sum[ch[x][1]];
  905. }
  906. void update( int x , long long v ){
  907. lzy[x] += v;
  908. sum[x] += s[x] * v;
  909. key[x] += v;
  910. }
  911. void ReleaseLabel( int x ){
  912. if( lzy[x] ){
  913. if( ch[x][0] ) update( ch[x][0] , lzy[x] );
  914. if( ch[x][1] ) update( ch[x][1] , lzy[x] );
  915. lzy[x] = 0;
  916. }
  917. }
  918. void rotate( int x, int d ){
  919. int y = fa[x];
  920. //cout << "y is " << y << " lzy is " << lzy[y] << endl;
  921. ReleaseLabel( y );
  922. ReleaseLabel( x );
  923. ch[y][d ^ 1] = ch[x][d];
  924. if ( ch[x][d]) fa[ch[x][d]] = y;
  925. fa[x] = fa[y];
  926. if (fa[y]){
  927. if (y == ch[fa[y]][d]) ch[fa[y]][d] = x;
  928. else ch[fa[y]][d ^ 1] = x;
  929. }
  930. ch[x][d] = y , fa[y] = x;
  931. up( y );
  932. up( x );
  933. }
  934. // Splay x to target's son
  935. void Splay( int x , int target ){
  936. ReleaseLabel( x ); // Very Improtant !!!!
  937. while( fa[x] != target ){
  938. int y = fa[x];
  939. if( x == ch[y][0] ){
  940. if( fa[y] != target && y == ch[fa[y]][0])
  941. rotate( y , 1 );
  942. rotate( x , 1 );
  943. }else{
  944. if( fa[y] != target && y == ch[fa[y]][1])
  945. rotate( y , 0 );
  946. rotate( x , 0 );
  947. }
  948. }
  949. if( !target ) root = x;
  950. }
  951. int insert( int & x , int id , int val , int par = 0 ){
  952. int rs;
  953. if( x == 0 ){
  954. x = ++ tot;
  955. rs = x;
  956. init( tot , id , val , par );
  957. }else{
  958. int cur = x;
  959. ReleaseLabel( cur );
  960. if( id < index[x] ) rs = insert( ch[x][0] , id , val , x );
  961. else rs = insert( ch[x][1] , id , val , x );
  962. }
  963. up( x );
  964. return rs;
  965. }
  966. int pred( int t , int v ){
  967. if( t == 0 ) return -1;
  968. if( v <= index[t] ) return pred( ch[t][0] , v );
  969. else{
  970. int rs = pred( ch[t][1] , v );
  971. if( rs == -1 ) return t;
  972. return rs;
  973. }
  974. }
  975. int succ( int t , int v ){
  976. if( t == 0 ) return -1;
  977. if( v >= index[t] ) return succ( ch[t][1] , v );
  978. else{
  979. int rs = succ( ch[t][0] , v );
  980. if( rs == -1 ) return t;
  981. return rs;
  982. }
  983. }
  984. // After GotSegement( l , r ) must use Splay funtion to Modify son's information to the root
  985. int GetSegement( int l , int r ){
  986. int s1 = pred( root , l ) , s2 = succ( root , r );
  987. if( s1 == -1 && s2 == -1 ) return root;
  988. else if( s1 == -1 ){
  989. Splay( s2 , 0 );
  990. return ch[s2][0];
  991. }else if( s2 == -1 ){
  992. Splay( s1 , 0 );
  993. return ch[s1][1];
  994. }else{
  995. Splay( s1 , 0 );
  996. Splay( s2 , s1 );
  997. return ch[s2][0];
  998. }
  999. }
  1000. void Delete( int l , int r ){
  1001. int s1 = pred( root , l ) , s2 = succ( root , r );
  1002. if( s1 == -1 && s2 == -1 ){
  1003. fa[ch[root][0]] = 0;
  1004. fa[ch[root][1]] = 0;
  1005. root = 0;
  1006. }
  1007. else if( s1 == -1 ){
  1008. Splay( s2 , 0 );
  1009. fa[ch[s2][0]] = 0;
  1010. ch[s2][0] = 0;
  1011. up( s2 );
  1012. }else if( s2 == -1 ){
  1013. Splay( s1 , 0 );
  1014. fa[ch[s1][1]] = 0;
  1015. ch[s1][1] = 0 ;
  1016. up( s1 );
  1017. }else{
  1018. Splay( s1 , 0 );
  1019. Splay( s2 , s1 );
  1020. fa[ch[s2][0]] = 0;
  1021. ch[s2][0] = 0;
  1022. up( s2 );
  1023. up( s1 );
  1024. }
  1025. }
  1026. }splay;
  1027. FWT
  1028. #include <bits/stdc++.h>
  1029. using namespace std;
  1030. const int N = 1 << 20;
  1031. int a[N];
  1032. void tfand(int a[], int n) {
  1033. if(n == 1) return;
  1034. int x = n >> 1;
  1035. tfand(a, x); tfand(a + x, x);
  1036. for(int i = 0; i < x; ++ i)
  1037. a[i] += a[i + x];
  1038. }
  1039. void utfand(long long a[], int n) {
  1040. if(n == 1) return;
  1041. int x = n >> 1;
  1042. for(int i = 0; i < x; ++ i)
  1043. a[i] -= a[i + x];
  1044. utfand(a, x); utfand(a + x, x);
  1045. }
  1046. void tfor(int a[], int n) {
  1047. if(n == 1) return;
  1048. int x = n >> 1;
  1049. tfor(a, x); tfor(a + x, x);
  1050. for(int i = 0; i < x; ++ i)
  1051. a[i + x] += a[i];
  1052. }
  1053. void utfor(long long a[], int n) {
  1054. if(n == 1) return;
  1055. int x = n >> 1;
  1056. for(int i = 0; i < x; ++ i)
  1057. a[i + x] -= a[i];
  1058. utfor(a, x); utfor(a + x, x);
  1059. }
  1060. long long t[N];
  1061. void utfxor(long long a[], int n) {
  1062. if(n == 1) return;
  1063. int x = n >> 1;
  1064. for(int i = 0; i < x; ++ i) {
  1065. t[i] = (a[i] + a[i + x]) >> 1;
  1066. t[i + x] = (a[i + x] - a[i]) >> 1;
  1067. }
  1068. memcpy(a, t, n * sizeof(long long));
  1069. utfxor(a, x); utfxor(a + x, x);
  1070. }
  1071. int tmp[N];
  1072. void tfxor(int a[], int n) {
  1073. if(n == 1) return;
  1074. int x = n >> 1;
  1075. tfxor(a, x); tfxor(a + x, x);
  1076. for(int i = 0; i < x; ++ i) {
  1077. tmp[i] = a[i] - a[i + x];
  1078. tmp[i + x] = a[i] + a[i + x];
  1079. }
  1080. memcpy(a, tmp, n * sizeof(int));
  1081. }
  1082. long long b[N];
  1083. int c[N];
  1084. int main() {
  1085. int T, cas = 1;
  1086. scanf("%d", &T);
  1087. while(T --) {
  1088. int n, op;
  1089. scanf("%d%d", &n, &op);
  1090. memset(a, 0, sizeof(a));
  1091. for(int i = 0; i < n; ++ i) {
  1092. scanf("%d", c + i);
  1093. ++ a[c[i]];
  1094. }
  1095. if(op == 1) {
  1096. tfand(a, 1 << 20);
  1097. } else if(op == 2) {
  1098. tfxor(a, 1 << 20);
  1099. } else {
  1100. tfor(a, 1 << 20);
  1101. }
  1102. for(int i = 0; i < 1 << 20; ++ i)
  1103. b[i] = (long long)a[i] * a[i];
  1104. if(op == 1) {
  1105. utfand(b, 1 << 20);
  1106. } else if(op == 2) {
  1107. utfxor(b, 1 << 20);
  1108. } else {
  1109. utfor(b, 1 << 20);
  1110. }
  1111. if(op != 2) {
  1112. for(int i = 0; i < n; ++ i) -- b[c[i]];
  1113. }
  1114. int ans = 0;
  1115. for(int i = (1 << 20) - 1; i >= 0; -- i) if(b[i]) {
  1116. ans = i;
  1117. break;
  1118. }
  1119. printf("Case #%d: %d\n", cas ++, ans);
  1120. }
  1121. return 0;
  1122. }
  1123. 博弈论
  1124. Nim Game
  1125. 最经典最基础的博弈.
  1126. n堆石子,双方轮流从任意一堆石子中取出至少一个,不能取的人输.
  1127. 对于一堆x个石子的情况,容易用归纳法得到SG(x)=x.
  1128. 所以所有石子个数的异或和为0是必败态,否则为必胜态.
  1129. Bash Game
  1130. 每人最多一次只能取m个石子,其他规则同Nim Game.
  1131. 依旧数学归纳…SG(x)=xmod(m+1).
  1132. NimK Game
  1133. 每人一次可以从最多K堆石子中取出任意多个,其他规则同Nim Game.
  1134. 结论:在二进制下各位上各堆石子的数字之和均为(K+1)的倍数的话则为必败态,否则为必胜态.
  1135. 这个证明要回到原始的方法上去.
  1136. 补:这个游戏还可以推广,即一个由n个子游戏组成的游戏,每次可以在最多K个子游戏中进行操作.
  1137. 然后只要把结论中各堆石子的个数改为各个子游戏的SG值即可,证明也还是一样的.
  1138. Anti-Nim Game
  1139. 似乎又叫做Misère Nim.
  1140. 不能取的一方获胜,其他规则同Nim Game.
  1141. 关于所谓的”Anti-SG游戏”及”SJ定理”贾志鹏的论文上有详细说明,不过似乎遇到并不多.
  1142. 结论是一个状态是必胜态当且仅当满足以下条件之一:
  1143. SG值不为0且至少有一堆石子数大于1;
  1144. SG值为0且不存在石子数大于1的石子堆.
  1145. Staircase Nim
  1146. 每人一次可以从第一堆石子中取走若干个,或者从其他石子堆的一堆中取出若干个放到左边一堆里(没有石子的石子堆不会消失),其他规则同Nim Game.
  1147. 这个游戏的结论比较神奇:
  1148. 当且仅当奇数编号堆的石子数异或和为0时为必败态.
  1149. 简单的理解是从偶数编号堆中取石子对手又可以放回到奇数编号堆中,而且不会让对手不能移动.比较意识流,然而可以归纳证明.
  1150. Wythoff Game
  1151. 有两堆石子,双方轮流从某一堆取走若干石子或者从两堆中取走相同数目的石子,不能取的人输.
  1152. 容易推理得出对任意自然数k,都存在唯一的一个必败态使得两堆石子数差为k,设其为Pk=(ak,bk),表示石子数分别为ak,bk(akbk).
  1153. 那么ak为在Pk0(k0<k)中未出现过的最小自然数,bk=ak+k.
  1154. 数学班的说,用Betty定理以及显然的单调性就可以推出神奇的结论:
  1155. ak=⌊k5√+12⌋,bk=⌊k5√+32⌋.
  1156. Take & Break
  1157. n堆石子,双方轮流取出一堆石子,然后新增两堆规模更小的石子堆(可以没有石子),无法操作者输.
  1158. 这个游戏似乎只能暴力SG,知道一下就好.
  1159. 树上删边游戏
  1160. 给出一个有n个结点的树,有一个点作为树的根节点,双方轮流从树中删去一条边边,之后不与根节点相连的部分将被移走,无法操作者输.
  1161. 结论是叶子结点的SG值为0,其他结点SG值为其每个儿子结点SG值加1后的异或和,证明也并不复杂.
  1162. 下面两个游戏我不太会,于是偷懒引用贾志豪《组合游戏略述——浅谈 SG 游戏的若干拓展及变形》中的内容了.
  1163. 翻硬币游戏
  1164. n枚硬币排成一排,有的正面朝上,有的反面朝上。
  1165. 游戏者根据某些约束翻硬币(如:每次只能翻一或两枚,或者每次只能翻连续的几枚),但他所翻动的硬币中,最右边的必须是从正面翻到反面。
  1166. 谁不能翻谁输。
  1167. 需要先开动脑筋把游戏转化为其他的取石子游戏之类的,然后用如下定理解决:
  1168. 局面的 SG 值等于局面中每个正面朝上的棋子单一存在时的 SG 值的异或和。
  1169. 无向图删边游戏
  1170. 一个无向连通图,有一个点作为图的根。
  1171. 游戏者轮流从图中删去边, 删去一条边后,不与根节点相连的部分将被移走。
  1172. 谁无路可走谁输。
  1173. 对于这个模型,有一个著名的定理——Fusion Principle:
  1174. 我们可以对无向图做如下改动:将图中的任意一个偶环缩成一个新点,任意一个奇环缩成一个新点加一个新边;所有连到原先环上的边全部改为与新点相连。 这样的改动不会影响图的 SG 值。
  1175. 数学
  1176. 奇怪的数学公式系列:
  1177. 欧拉函数:
  1178. 在数论,对正整数n,欧拉函数是小于n的数中与n互质的数的数目。此函数以其首名研究者欧拉命名,它又称为Euler's totient function、φ函数、欧拉商数等。 例如φ(8)=4,因为1,3,5,7均和8互质。 从欧拉函数引伸出来在环论方面的事实和拉格朗日定理构成了欧拉定理的证明。
  1179. φ函数的值:通式:φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,x是不为0的整数。φ(1)=1(唯一和1互质的数(小于等于1)就是1本身)。 (注意:每种质因数只一个。比如12=2*2*3那么φ(12)=12*(1-1/2)*(1-1/3)=4
  1180. 若n是质数p的k次幂,φ(n)=p^k-p^(k-1)=(p-1)p^(k-1),因为除了p的倍数外,其他数都跟n互质。
  1181. 设n为正整数,以 φ(n)表示不超过n且与n互素的正整数的个数,称为n的欧拉函数值,这里函数
  1182. φ:N→N,n→φ(n)称为欧拉函数。
  1183. 欧拉函数是积性函数——若m,n互质,φ(mn)=φ(m)φ(n)。
  1184. 特殊性质:当n为奇数时,φ(2n)=φ(n), 证明与上述类似。
  1185. 若n为质数则φ(n)=n-1。
  1186. long long phi[maxn];
  1187. void phi1()
  1188. {
  1189. memset(phi,0,sizeof(phi));
  1190. phi[1]=1;
  1191. for(long long i=2;i<=n;i++)
  1192. {
  1193. if(!phi[i])
  1194. {
  1195. for(long long j=i;j<=n;j+=i)
  1196. {
  1197. if(!phi[j]) phi[j]=j;
  1198. phi[j]=phi[j]/i*(i-1);
  1199. }
  1200. }
  1201. }
  1202. }
  1203. 另外一种:
  1204. long long phi(long long n)
  1205. {
  1206. long long tmp=n;
  1207. for(long long i=2;i*i<=n;i++)
  1208. if(n%i==0)
  1209. {
  1210. tmp/=i;tmp*=i-1;
  1211. while(n%i==0)n/=i;
  1212. }
  1213. if(n!=1)tmp/=n,tmp*=n-1;
  1214. return tmp;
  1215. }
  1216. 排列组合
  1217. #include<bits/stdc++.h>
  1218. using namespace std;
  1219. const int maxn = 1e6+7;
  1220. const int mod = 1e9+7;
  1221. long long fac[maxn];
  1222. long long qpow(long long a,long long b)
  1223. {
  1224. long long ans=1;a%=mod;
  1225. for(long long i=b;i;i>>=1,a=a*a%mod)
  1226. if(i&1)ans=ans*a%mod;
  1227. return ans;
  1228. }
  1229. long long C(long long n,long long m)
  1230. {
  1231. if(m>n||m<0)return 0;
  1232. long long s1=fac[n],s2=fac[n-m]*fac[m]%mod;
  1233. return s1*qpow(s2,mod-2)%mod;
  1234. }
  1235. int main()
  1236. {
  1237. fac[0]=1;
  1238. for(int i=1;i<maxn;i++)
  1239. fac[i]=fac[i-1]*i%mod;
  1240. }
  1241. 逆元
  1242. int gcd(int a, int b, int& x, int& y) {
  1243. if (!a) {
  1244. x = 0, y = 1;
  1245. return b;
  1246. }
  1247. int xx, yy, g = gcd(b % a, a, xx, yy);
  1248. x = yy - b / a * xx;
  1249. y = xx;
  1250. return g;
  1251. }
  1252. inline int normal(int n) {
  1253. n %= mod;
  1254. (n < 0) && (n += mod);
  1255. return n;
  1256. }
  1257. inline int inv(int a) {
  1258. int x, y;
  1259. assert(gcd(a, mod, x, y) == 1);
  1260. return normal(x);
  1261. }
  1262. inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
  1263. inline int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }
  1264. inline int mul(int a, int b) { return int(a * 1ll * b % mod); }
  1265. inline int _div(int a, int b) { return mul(a, inv(b)); }
  1266. 统计二进制有多少个1
  1267. cnt[i]=cnt[i>>1]+(i&1);
  1268. popcount(int x){
  1269. return cnt[x>>16]+cnt[x&((1<<16)-1)];
  1270. }
  1271. 网络流
  1272. namespace NetFlow
  1273. {
  1274. const int MAXN=100000,MAXM=100000,inf=1e9;
  1275. struct Edge
  1276. {
  1277. int v,c,f,nx;
  1278. Edge() {}
  1279. Edge(int v,int c,int f,int nx):v(v),c(c),f(f),nx(nx) {}
  1280. } E[MAXM];
  1281. int G[MAXN],cur[MAXN],pre[MAXN],dis[MAXN],gap[MAXN],N,sz;
  1282. void init(int _n)
  1283. {
  1284. N=_n,sz=0; memset(G,-1,sizeof(G[0])*N);
  1285. }
  1286. void link(int u,int v,int c)
  1287. {
  1288. E[sz]=Edge(v,c,0,G[u]); G[u]=sz++;
  1289. E[sz]=Edge(u,0,0,G[v]); G[v]=sz++;
  1290. }
  1291. int ISAP(int S,int T)
  1292. {//S -> T
  1293. int maxflow=0,aug=inf,flag=false,u,v;
  1294. for (int i=0;i<N;++i)cur[i]=G[i],gap[i]=dis[i]=0;
  1295. for (gap[S]=N,u=pre[S]=S;dis[S]<N;flag=false)
  1296. {
  1297. for (int &it=cur[u];~it;it=E[it].nx)
  1298. {
  1299. if (E[it].c>E[it].f&&dis[u]==dis[v=E[it].v]+1)
  1300. {
  1301. if (aug>E[it].c-E[it].f) aug=E[it].c-E[it].f;
  1302. pre[v]=u,u=v; flag=true;
  1303. if (u==T)
  1304. {
  1305. for (maxflow+=aug;u!=S;)
  1306. {
  1307. E[cur[u=pre[u]]].f+=aug;
  1308. E[cur[u]^1].f-=aug;
  1309. }
  1310. aug=inf;
  1311. }
  1312. break;
  1313. }
  1314. }
  1315. if (flag) continue;
  1316. int mx=N;
  1317. for (int it=G[u];~it;it=E[it].nx)
  1318. {
  1319. if (E[it].c>E[it].f&&dis[E[it].v]<mx)
  1320. {
  1321. mx=dis[E[it].v]; cur[u]=it;
  1322. }
  1323. }
  1324. if ((--gap[dis[u]])==0) break;
  1325. ++gap[dis[u]=mx+1]; u=pre[u];
  1326. }
  1327. return maxflow;
  1328. }
  1329. bool bfs(int S,int T)
  1330. {
  1331. static int Q[MAXN]; memset(dis,-1,sizeof(dis[0])*N);
  1332. dis[S]=0; Q[0]=S;
  1333. for (int h=0,t=1,u,v,it;h<t;++h)
  1334. {
  1335. for (u=Q[h],it=G[u];~it;it=E[it].nx)
  1336. {
  1337. if (dis[v=E[it].v]==-1&&E[it].c>E[it].f)
  1338. {
  1339. dis[v]=dis[u]+1; Q[t++]=v;
  1340. }
  1341. }
  1342. }
  1343. return dis[T]!=-1;
  1344. }
  1345. int dfs(int u,int T,int low)
  1346. {
  1347. if (u==T) return low;
  1348. int ret=0,tmp,v;
  1349. for (int &it=cur[u];~it&&ret<low;it=E[it].nx)
  1350. {
  1351. if (dis[v=E[it].v]==dis[u]+1&&E[it].c>E[it].f)
  1352. {
  1353. if (tmp=dfs(v,T,min(low-ret,E[it].c-E[it].f)))
  1354. {
  1355. ret+=tmp; E[it].f+=tmp; E[it^1].f-=tmp;
  1356. }
  1357. }
  1358. }
  1359. if (!ret) dis[u]=-1; return ret;
  1360. }
  1361. int dinic(int S,int T)
  1362. {
  1363. int maxflow=0,tmp;
  1364. while (bfs(S,T))
  1365. {
  1366. memcpy(cur,G,sizeof(G[0])*N);
  1367. while (tmp=dfs(S,T,inf)) maxflow+=tmp;
  1368. }
  1369. return maxflow;
  1370. }
  1371. }
  1372. 费用流
  1373. struct ZKW_MinCostMaxFlow{
  1374. const static int maxn = 1e5 + 50;
  1375. const static int maxE = 1e5 + 50;
  1376. const static int INF = 0x3f3f3f3f;
  1377. struct Edge{
  1378. int to,next,cap,flow,cost;
  1379. Edge(int _to=0,int _next=0,int _cap=0,int _flow=0,int _cost=0):
  1380. to(_to),next(_next),cap(_cap),flow(_flow),cost(_cost){}
  1381. }edge[maxE * 2];
  1382. int head[maxn],tot;
  1383. int cur[maxn];
  1384. int dis[maxn];
  1385. bool vis[maxn];
  1386. int ss,tt,N;
  1387. int min_cost,max_flow;
  1388. void init(int N){
  1389. tot=0;
  1390. for( int i = 0 ; i < N ; ++ i ) head[i] = -1;
  1391. }
  1392. int addedge(int u,int v,int cap,int cost){
  1393. edge[tot]=Edge(v,head[u],cap,0,cost);
  1394. int rs = tot;
  1395. head[u]=tot++;
  1396. edge[tot]=Edge(u,head[v],0,0,-cost);
  1397. head[v]=tot++;
  1398. return rs;
  1399. }
  1400. int aug(int u,int flow){
  1401. if(u==tt) return flow;
  1402. vis[u]=true;
  1403. for(int i=cur[u];i!=-1;i=edge[i].next){
  1404. int v=edge[i].to;
  1405. if( edge[i].cap>edge[i].flow && !vis[v] && dis[u]==dis[v]+edge[i].cost ){
  1406. int tmp=aug(v,min(flow,edge[i].cap-edge[i].flow));
  1407. edge[i].flow+=tmp;
  1408. edge[i^1].flow-=tmp;
  1409. cur[u]=i;
  1410. if(tmp) return tmp;
  1411. }
  1412. }
  1413. return 0;
  1414. }
  1415. bool modify_label(){
  1416. int d=INF;
  1417. for(int u=0;u<N;u++){
  1418. if(vis[u])
  1419. for(int i=head[u];i!=-1;i=edge[i].next){
  1420. int v=edge[i].to;
  1421. if(edge[i].cap>edge[i].flow && !vis[v])
  1422. d=min(d,dis[v]+edge[i].cost-dis[u]);
  1423. }
  1424. }
  1425. if(d==INF) return false;
  1426. for(int i=0;i<N;i++)
  1427. if(vis[i]){
  1428. vis[i]=false;
  1429. dis[i]+=d;
  1430. }
  1431. return true;
  1432. }
  1433. pair < int , int > mincostmaxflow(int start,int ed,int n ){
  1434. ss=start,tt=ed,N=n;
  1435. min_cost=max_flow=0;
  1436. for(int i=0;i<n;i++) dis[i]=0;
  1437. while(1){
  1438. for(int i=0;i<n;i++) cur[i]=head[i];
  1439. while(1){
  1440. for(int i=0;i<n;i++) vis[i]=false;
  1441. int tmp=aug(ss,INF);
  1442. if(tmp==0) break;
  1443. max_flow+=tmp;
  1444. min_cost+=tmp*dis[ss];
  1445. }
  1446. if(!modify_label()) break;
  1447. }
  1448. return mp( max_flow , min_cost );
  1449. }
  1450. }solver;
  1451. ////////////////////////另外一种
  1452. const int inf = 1e9;
  1453. const int MAXN = 10000;
  1454. const int MAXM = 100000;
  1455. const int INF = 0x3f3f3f3f;
  1456. struct Edge
  1457. {
  1458. int to, next, cap, flow, cost;
  1459. int x, y;
  1460. } edge[MAXM],HH[MAXN],MM[MAXN];
  1461. int head[MAXN],tol;
  1462. int pre[MAXN],dis[MAXN];
  1463. bool vis[MAXN];
  1464. int N, M;
  1465. char map[MAXN][MAXN];
  1466. void init()
  1467. {
  1468. N = MAXN;
  1469. tol = 0;
  1470. memset(head, -1, sizeof(head));
  1471. }
  1472. void addedge(int u, int v, int cap, int cost)//左端点,右端点,容量,花费
  1473. {
  1474. edge[tol]. to = v;
  1475. edge[tol]. cap = cap;
  1476. edge[tol]. cost = cost;
  1477. edge[tol]. flow = 0;
  1478. edge[tol]. next = head[u];
  1479. head[u] = tol++;
  1480. edge[tol]. to = u;
  1481. edge[tol]. cap = 0;
  1482. edge[tol]. cost = -cost;
  1483. edge[tol]. flow = 0;
  1484. edge[tol]. next = head[v];
  1485. head[v] = tol++;
  1486. }
  1487. bool spfa(int s, int t)
  1488. {
  1489. queue<int>q;
  1490. for(int i = 0; i < N; i++)
  1491. {
  1492. dis[i] = INF;
  1493. vis[i] = false;
  1494. pre[i] = -1;
  1495. }
  1496. dis[s] = 0;
  1497. vis[s] = true;
  1498. q.push(s);
  1499. while(!q.empty())
  1500. {
  1501. int u = q.front();
  1502. q.pop();
  1503. vis[u] = false;
  1504. for(int i = head[u]; i != -1; i = edge[i]. next)
  1505. {
  1506. int v = edge[i]. to;
  1507. if(edge[i]. cap > edge[i]. flow &&
  1508. dis[v] > dis[u] + edge[i]. cost )
  1509. {
  1510. dis[v] = dis[u] + edge[i]. cost;
  1511. pre[v] = i;
  1512. if(!vis[v])
  1513. {
  1514. vis[v] = true;
  1515. q.push(v);
  1516. }
  1517. }
  1518. }
  1519. }
  1520. if(pre[t] == -1) return false;
  1521. else return true;
  1522. }
  1523. //返回的是最大流, cost存的是最小费用
  1524. int minCostMaxflow(int s, int t, int &cost)
  1525. {
  1526. int flow = 0;
  1527. cost = 0;
  1528. while(spfa(s,t))
  1529. {
  1530. int Min = INF;
  1531. for(int i = pre[t]; i != -1; i = pre[edge[i^1]. to])
  1532. {
  1533. if(Min > edge[i]. cap - edge[i]. flow)
  1534. Min = edge[i]. cap - edge[i]. flow;
  1535. }
  1536. for(int i = pre[t]; i != -1; i = pre[edge[i^1]. to])
  1537. {
  1538. edge[i]. flow += Min;
  1539. edge[i^1]. flow -= Min;
  1540. cost += edge[i]. cost * Min;
  1541. }
  1542. flow += Min;
  1543. }
  1544. return flow;
  1545. }
  1546. SBT
  1547. struct SBT{
  1548. const static int maxn = 1e5 + 15;
  1549. int lft[maxn] , rht[maxn] , key[maxn] , s[maxn] , tot , root ;
  1550. void init(){ tot = root = 0 ; }
  1551. void init( int x , int val = 0 ){
  1552. lft[x] = rht[x] = 0 , key[x] = val , s[x] = 1;
  1553. }
  1554. inline void up(int x){
  1555. s[x] = s[lft[x]] + s[rht[x]] + 1;
  1556. }
  1557. void lr(int &t){
  1558. int k = rht[t];
  1559. rht[t] = lft[k];
  1560. lft[k] = t;
  1561. s[k] = s[t];
  1562. up(t);
  1563. t = k;
  1564. }
  1565. void rr(int &t){
  1566. int k = lft[t];
  1567. lft[t] = rht[k];
  1568. rht[k]= t;
  1569. s[k] = s[t];
  1570. up(t);
  1571. t = k;
  1572. }
  1573. void Maintain(int &t,bool dir){
  1574. if(dir == false){
  1575. if(s[lft[lft[t]]] > s[rht[t]])
  1576. rr(t);
  1577. else if(s[rht[lft[t]]] > s[rht[t]]){
  1578. lr(lft[t]);
  1579. rr(t);
  1580. }
  1581. else return;
  1582. }
  1583. else{
  1584. if(s[rht[rht[t]]] > s[lft[t]]) lr(t);
  1585. else if(s[lft[rht[t]]] > s[lft[t]]){
  1586. rr(rht[t]);
  1587. lr(t);
  1588. }
  1589. else return;
  1590. }
  1591. Maintain(lft[t],false);
  1592. Maintain(rht[t],true);
  1593. Maintain(t,true);
  1594. Maintain(t,false);
  1595. }
  1596. void Insert( int & t , int val ){
  1597. if( t == 0 ){
  1598. t = ++ tot;
  1599. init( t , val );
  1600. }else{
  1601. ++ s[t];
  1602. if( val < key[t] ) Insert( lft[t] , val );
  1603. else Insert( rht[t] , val );
  1604. Maintain( t , val >= key[t] );
  1605. }
  1606. }
  1607. // 删除操作必须保证元素存在
  1608. int Delete(int &t , int v){
  1609. int ret = 0;
  1610. s[t] --;
  1611. if((v == key[t]) || (v<key[t] && lft[t] == 0) ||(v > key[t] && rht[t] == 0) ){
  1612. ret = key[t];
  1613. if(lft[t] == 0 || rht[t] == 0) t = lft[t] + rht[t];
  1614. else key[t] = Delete(lft[t],key[t] + 1);
  1615. }
  1616. else{
  1617. if(v < key[t]) ret = Delete(lft[t] , v);
  1618. else ret = Delete(rht[t] , v);
  1619. }
  1620. return ret;
  1621. }
  1622. bool find( int t , int val ){
  1623. if( t == 0 ) return false;
  1624. else if( key[t] == val ) return true;
  1625. else if( val < key[t] ) return find( lft[t] , val );
  1626. else return find( rht[t] , val );
  1627. }
  1628. void preorder( int x ){
  1629. if( lft[x] ) preorder( lft[x] );
  1630. printf("%d " , key[x]);
  1631. if( rht[x] ) preorder( rht[x] );
  1632. }
  1633. int size(){
  1634. return s[root];
  1635. }
  1636. // 查第 k 小 , 必须保证合法
  1637. int kth( int x , int k ){
  1638. if( k == s[lft[x]] + 1 ) return key[x];
  1639. else if( k <= s[lft[x]] ) return kth( lft[x] , k );
  1640. else return kth( rht[x] , k - s[lft[x]] - 1 );
  1641. }
  1642. //找前驱
  1643. int pred( int t , int v ){
  1644. if( t == 0 ) return v;
  1645. else{
  1646. if( v <= key[t] ) return pred( lft[t] , v );
  1647. else{
  1648. int ans = pred( rht[t] , v );
  1649. if( ans == v ) ans = key[t];
  1650. return ans;
  1651. }
  1652. }
  1653. }
  1654. // 严格小于 v 的有多少个
  1655. int less( int t , int v ){
  1656. if( t == 0 ) return 0;
  1657. if( v <= key[t] ) return less( lft[t] , v );
  1658. else return s[lft[t]] + 1 + less( rht[t] , v );
  1659. }
  1660. //找后继
  1661. int succ( int t , int v ){
  1662. if( t == 0 ) return v;
  1663. else{
  1664. if( v >= key[t] ) return succ( rht[t] , v );
  1665. else{
  1666. int ans = succ( lft[t] , v );
  1667. if( ans == v ) ans = key[t];
  1668. return ans;
  1669. }
  1670. }
  1671. }
  1672. }sbt;
  1673. 行列式
  1674. int Det(){
  1675. int cur = 0 , sgn = 1;
  1676. for( int i = 0 ; i < N ; ++ i){
  1677. int nxt = -1;
  1678. for( int j = cur ; j < N ; ++ j) if( mat[j][i]){
  1679. nxt = j ;
  1680. break ;
  1681. }
  1682. if( nxt == -1 ) return 0;
  1683. if( nxt != cur ) sgn = - sgn;
  1684. for( int j = 0 ; j < N ; ++ j) swap( mat[cur][j] , mat[nxt][j] );
  1685. for( int j = cur + 1 ; j < N ; ++ j){
  1686. while( mat[j][i] ){
  1687. int x = mat[j][i] / mat[cur][i];
  1688. if( x ){
  1689. for( int k = i ; k < N ; ++ k){
  1690. mat[j][k] -= mul( mat[cur][k] , x ) ;
  1691. Maintain(mat[j][k]);
  1692. }
  1693. }else{
  1694. for( int k = i ; k < N ; ++ k) swap( mat[j][k] , mat[cur][k] );
  1695. sgn = - sgn;
  1696. }
  1697. }
  1698. }
  1699. ++ cur;
  1700. }
  1701. int ans = 1;
  1702. for( int i = 0 ; i < N ; ++ i ) ans = mul( ans , mat[i][i] );
  1703. if( sgn == -1 ) ans = P - ans;
  1704. return ans;
  1705. }
  1706. double Det(){
  1707. //-- N;
  1708. double ans = 1;
  1709. int cur = 0 , sgn = 1;
  1710. for(int i = 0 ; i < N ; ++ i){
  1711. int nxt = -1;
  1712. for( int j = cur ; j < N ; ++ j) if( fabs(mat[j][i]) > eps ){
  1713. nxt = j ;
  1714. break ;
  1715. }
  1716. if( nxt == -1 ) continue;
  1717. for( int j = 0 ; j < N ; ++ j) swap( mat[cur][j] , mat[nxt][j] );
  1718. if( nxt != cur ) sgn = - sgn;
  1719. for( int j = 0 ; j < N ; ++ j ) if( j != cur ){
  1720. double s = mat[j][i] / mat[cur][i];
  1721. for( int k = i ; k < N ; ++ k) mat[j][k] -= s * mat[cur][k];
  1722. }
  1723. ++ cur ;
  1724. }
  1725. for( int i = 0 ; i < N ; ++ i) ans = ans * mat[i][i];
  1726. return ans * sgn;
  1727. }

uestc_retarded 模板的更多相关文章

  1. Jade模板引擎让你飞

    写在前面:现在jade改名成pug了 一.安装 npm install jade 二.基本使用 1.简单使用 p hello jade! 渲染后: <p>hello jade!</p ...

  2. ABP入门系列(2)——通过模板创建MAP版本项目

    一.从官网创建模板项目 进入官网下载模板项目 依次按下图选择: 输入验证码开始下载 下载提示: 二.启动项目 使用VS2015打开项目,还原Nuget包: 设置以Web结尾的项目,设置为启动项目: 打 ...

  3. CMS模板应用调研问卷

    截止目前,已经有数十家网站与我们合作,进行了MIP化改造,在搜索结果页也能看到"闪电标"的出现.除了改造方面的问题,MIP项目组被问到最多的就是:我用了wordpress,我用了织 ...

  4. PHP-自定义模板-学习笔记

    1.  开始 这几天,看了李炎恢老师的<PHP第二季度视频>中的“章节7:创建TPL自定义模板”,做一个学习笔记,通过绘制架构图.UML类图和思维导图,来对加深理解. 2.  整体架构图 ...

  5. 【原创分享·微信支付】C# MVC 微信支付之微信模板消息推送

    微信支付之微信模板消息推送                    今天我要跟大家分享的是“模板消息”的推送,这玩意呢,你说用途嘛,那还是真真的牛逼呐.原因在哪?就是因为它是依赖微信生存的呀,所以他能不 ...

  6. OpenCV模板匹配算法详解

    1 理论介绍 模板匹配是在一幅图像中寻找一个特定目标的方法之一,这种方法的原理非常简单,遍历图像中的每一个可能的位置,比较各处与模板是否“相似”,当相似度足够高时,就认为找到了我们的目标.OpenCV ...

  7. 前端MVC学习总结(一)——MVC概要与angular概要、模板与数据绑定

    一.前端MVC概要 1.1.库与框架的区别 框架是一个软件的半成品,在全局范围内给了大的约束.库是工具,在单点上给我们提供功能.框架是依赖库的.AngularJS是框架而jQuery则是库. 1.2. ...

  8. ThinkPHP+Smarty模板中截取包含中英文混合的字符串乱码的解决方案

    好几天没写博客了,其实有好多需要总结的,因为最近一直在忙着做项目,但是困惑了几天的Smarty模板中截取包含中英文混合的字符串乱码的问题,终于解决了,所以记录下来,需要的朋友看一下: 出现乱码的原因: ...

  9. ThinkPHP 模板substr的截取字符串函数

    ThinkPHP 模板substr的截取字符串函数在Common/function.php加上以下代码 /** ** 截取中文字符串 **/ function msubstr($str, $start ...

随机推荐

  1. win10使用Composer-Setup安装Composer以及使用Composer安装Yii2最新版

    1:下载 ca-bundle.crt和cacert.pem 将这两个文件放在php目录下 2:php.ini中添加上述两个文件的路径 curl.cainfo=C:/xampp/php/ca-bundl ...

  2. <改变未来的九大算法>读书笔记二

    原理 数据库的一致性 1.事务和代办事项表把戏(预写日志记录) 1.代办事项表把戏:先把要执行的的操作写入硬件,即写日志.即使数据库操作错误,也可根据日志来纠正.对日志的操作具有等幂性,即日志中的每项 ...

  3. Xcode7.2 导入XMPP框架错误解决

    1.修改Build Settings 在 Header Search Paths 中添加: "/usr/include/libxml2" 在Other Linker Flags 中 ...

  4. ubuntu搭建svn服务器(转)

    在阿里云买了个服务器,想上传东西,samba不好用,想起来可以搭个svn用,找到了这篇. 1. 安装SVN apt-get install subversion 2. 建立svn仓库 1). 建立sv ...

  5. java后台开发传输乱码&&接口post传参失败

    起因: 前几天遇到的问题,才有时间记录,需求:本地生成xml形式的字符串以参数形式用post方法传送到对方的固定接口: 这个需求写的时候感觉很容易,本地测试的时候,也觉得很简单就过了,然后和对方联调的 ...

  6. php redis 代码实例

    <?phpheader("Content-type:text/html;charset=utf8");$redis = new redis();$redis ->con ...

  7. HTTP02--Http请求头及缓存知识

    一.常用工具 Linux下:curl命令,I参数可以查看http head信息. Firefox:Firebug.HttpFox 二.常见Http Head信息 三.浏览器缓存机制 使用ctrl+F5 ...

  8. ASP.NET Core 源码阅读笔记(5) ---Microsoft.AspNetCore.Routing路由

    这篇随笔讲讲路由功能,主要内容在项目Microsoft.AspNetCore.Routing中,可以在GitHub上找到,Routing项目地址. 路由功能是大家都很熟悉的功能,使用起来也十分简单,从 ...

  9. C#自学系列 - 开篇

    2014年即将过去,这一年我参加了不少面试,被问到了很多问题.回来总结下发现自己确实在基础方面有着很多的不足,还有很多东西是我不知道的.遂在下半年购入书籍若干,并系统的加以学习.我目前在看的书是Jon ...

  10. [芯片] 4、接口技术·实验四·串行接口8251A

    目录 一.实验目的和要求... 2 二.实验原理与背景... 3 三.实验具体的内容... 3 四.实验的代码说明... 4 五.实验结果的分析... 6 附录资料 一.实验目的和要求 学会8251芯 ...