
模板
心脏dance
求关注!!!求关注!!!安卓、后端学习记录,面试算法题(博主ACM区域赛银牌~~~水银嘻嘻~~~,蓝桥杯国一~~~),面试技术题。如果觉得博主写的好,菜鸡博主求关注~~~。 /*
呜呜呜~~大学的时候,写的博文中有些是借鉴的,若有侵权,请告知,立马删除。。。。 */
展开
-
java快读快输模板
很好看懂~,代码上面加了一个例子,很好懂!!import java.io.*;import java.util.*;public class 外挂 { static class FastScanner{//用于快速读入大量数据 BufferedReader br; StringTokenizer st; public FastScanner(InputStream in)...原创 2020-01-15 13:58:30 · 2104 阅读 · 0 评论 -
求在一个平面内有N个人,用一个W*H的矩形去围这些人(边上的也算), 求最大人数。(扫描线模板)
#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <queue>#include <map>#include <iostream>#include...原创 2019-07-28 17:36:37 · 310 阅读 · 0 评论 -
杜教BM模板
#include<bits/stdc++.h>using namespace std;#define rep(i,a,n) for (int i=a;i<n;i++)#define per(i,a,n) for (int i=n-1;i>=a;i--)#define pb push_back#define mp make_pair#define all(x) ...原创 2019-08-02 14:05:15 · 293 阅读 · 0 评论 -
求1-n中x(0-9)的个数
#include <iostream>#include <cstdio>using namespace std;typedef long long ll;ll count(ll n,ll x){//找1-n中x的个数,时间复杂度log(10,n) ll cnt=0,k; for (ll i = 1; k = n/i;i*=10){ ll high=k/10...原创 2019-08-14 17:14:56 · 268 阅读 · 0 评论 -
整除分块(模板)
复杂度for(int l=1,r;l<=n;l=r+1){ r=n/(n/l); ans+=(r-l+1)*(n/l);}很好理解,不解释了~~,实在不懂记住就好了!!原创 2019-08-20 16:35:45 · 419 阅读 · 0 评论 -
二次剩余求x^2=a(mod p) 的x模板
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;typedef long long ll;const int p=1e9+7;struct hh{ ll x,y; hh(){}; hh(ll _x,ll _y){ x=_x;y=_y;...原创 2019-08-15 19:20:26 · 896 阅读 · 0 评论 -
中国剩余定理(互质模板与非互质模板)
#include <iostream>#include <cstdio>using namespace std;typedef long long ll;void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){ if(!b){ d=a,x=1,y=0; } else{ ...原创 2019-08-16 17:08:33 · 240 阅读 · 0 评论 -
指数循环节例题(模板)
1. 2019南京网络赛super_log: 求(fuck[0]^fuck[1]^fuck[2]^...^fuck[b-1] mod m )>=b 其中fuck数组=a; 数据范围:1<=a<=1e6: 0<=b<=1e6,1<=m<=1e6上代码:#include <bits/stdc++.h>using namespace s...原创 2019-09-01 20:48:20 · 316 阅读 · 0 评论 -
中国剩余定理 非互质(java大数)
import java.math.BigInteger;import java.util.Scanner; public class Main { static BigInteger dd; static BigInteger xx; static BigInteger yy; static BigInteger []a = new BigInteger [1005]; st...原创 2019-12-27 14:27:49 · 347 阅读 · 0 评论 -
旋转点问题(计算几何模版)
#include <iostream>#include <algorithm>#include <cstdio>using namespace std;const double pi=acos(-1.0);struct hh{ double x,y;};hh zhuan(hh a,hh b,double p){//点a绕点b转p度 hh fu...原创 2019-12-27 14:27:42 · 714 阅读 · 0 评论 -
三点确定圆心和半径(模版)
struct Point2f{ double x,y;};struct CircleData{ Point2f center; double radius;};//方法一:通过其中两点的中垂线交点求圆心CircleData findCircle1(Point2f pt1, Point2f pt2, Point2f pt3){ //定义两个点,分别表示两个中点 Point2...原创 2019-12-27 14:27:12 · 4533 阅读 · 0 评论 -
Pollard-Rho算法(模板)
对于每个数字检验是否是质数,是质数就输出Prime;如果不是质数,输出它最大的质因子是哪个。#include<bits/stdc++.h>using namespace std; long long fast_mul(long long x,long long y,long long p)//return x*y mod p{ return (__int128)x...原创 2019-12-29 20:55:34 · 278 阅读 · 0 评论 -
BSGS模板(a^x==b(mod c))
a^x==b(mod c) 可以求满足的最小自然数x#include <iostream>#include <algorithm>#include <cmath>#include <tr1/unordered_map>using namespace std::tr1;using namespace std;void exgcd(i...原创 2019-12-30 15:21:18 · 205 阅读 · 0 评论 -
背包问题
01背包:for (int i = 0; i < n;i++){ for (int j = vv; j >= w[i];j--){ dp[j]=max(dp[j],dp[j-w[i]]+v[i]); }}cout << dp[vv] << endl;// vv代表总体积,w[i]代表第i个物品重量,v[i]代表第i个物品价值,dp[vv]代表...原创 2018-08-24 17:09:44 · 240 阅读 · 0 评论 -
求次小生成树权值模板
n代表点m代表边,网上大佬的代码,先当模板了,感觉这也像是模板。。。#include<cmath>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define inf 0x7f7f7f7fusing namespace std;...原创 2018-12-17 21:40:53 · 165 阅读 · 0 评论 -
组合数
#include <iostream>#include <cstdio>using namespace std;typedef long long ll;const int MAX = 1e6+100;const int MAXX = 2e3+100;int mod;int dp[MAXX][MAXX];int f[MAX],finv[MAX],inv[M...原创 2019-04-06 20:49:30 · 459 阅读 · 0 评论 -
母函数
#include<cstdio>typedef long long LL;const int N = 100 + 5;//假如题目只问到100为止 const int MAX = 3;//题目只有1,2,3这3种邮票 LL c1[N], c2[N];//c2是临时合并的多项式,c1是最终合并的多项式 int n;void init(){ c1[0] = 1;//一...原创 2019-04-06 21:27:06 · 115 阅读 · 0 评论 -
卢卡斯定理
求C(n, m) % (p1*p2*p3*...*pk)的值范围:1≤m≤n≤1e18,1≤k≤10,pi≤1e5,保证p1*p2*p3*...*pk≤1e18#include<cstdio>typedef long long LL;const int N = 100000 + 5;LL mul(LL a, LL b, LL p){//快速乘,计算a*b%p ...原创 2019-04-06 21:40:59 · 162 阅读 · 0 评论 -
康托展开(hdu1430)
在魔方风靡全球之后不久,Rubik先生发明了它的简化版——魔板。魔板由8个同样大小的方块组成,每个方块颜色均不相同,可用数字1-8分别表示。任一时刻魔板的状态可用方块的颜色序列表示:从魔板的左上角开始,按顺时针方向依次写下各方块的颜色代号,所得到的数字序列即可表示此时魔板的状态。例如,序列(1,2,3,4,5,6,7,8)表示魔板状态为:1 2 3 48 7 6 5对于魔板,可施加三种不同的...原创 2019-04-06 21:45:46 · 540 阅读 · 0 评论 -
米勒罗宾算法:判断一个大数是不是素数
验证:哥德巴赫猜想#include <iostream>#include <algorithm>#include <cstdio>#include <ctime>#include <cmath>using namespace std;typedef unsigned long long LL;const int N ...原创 2019-06-29 19:59:47 · 896 阅读 · 0 评论 -
浅谈线性基(线性基模板整理)
1.求区间任意数组合异或的最大最小值,求区间任意组合的异或值是否有k这个值:#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int MAX = 5e5+10;int a[MAX];int p[MAX][31],pos[MAX][31...原创 2019-07-23 17:08:58 · 553 阅读 · 1 评论 -
(后缀数组)给你一个字符串,求出现次数在L到R次之间的子串的个数。
#include<bits/stdc++.h>#define lson rt<<1#define rson rt<<1|1#define rank rausing namespace std;const int maxn=1e5+10;const int INF=1e9+7;typedef long long ll;char s[maxn];...原创 2019-08-02 15:35:26 · 938 阅读 · 0 评论 -
RMQ模板(找区间最小值及其下标)
#include <iostream>#include <cstring>#include <cmath> #include <cstdio>#include <vector>using namespace std;const int MAX = 1e5+100;struct cao{ int l,r;}fuck[MA...原创 2019-07-30 16:21:01 · 390 阅读 · 0 评论 -
比较骚的快速幂模板
ll mul(ll a,ll b,ll c){ ll ans=0; while(b) { if(b&amp;amp;amp;amp;amp;1) { ans=(ans+a)%c; } a=(a&amp;amp;amp;amp;lt;&amp;amp;amp;amp;lt;1)%c; b&amp;a原创 2018-07-26 19:58:03 · 185 阅读 · 0 评论