zoukankan      html  css  js  c++  java
  • 实现技巧

    #include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <vector>
    #include <cstdio>
    #include <string>
    #include <cmath>
    #include <queue>
    #include <set>
    #include <map>
    #include <complex>
    using namespace std;
    typedef long long ll;
    typedef long double db;
    typedef pair<int,int> pii;
    typedef vector<int> vi;
    #define de(x) cout << #x << "=" << x << endl
    #define rep(i,a,b) for(int i=a;i<(b);++i)
    #define all(x) (x).begin(),(x).end()
    #define sz(x) (int)(x).size()
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    const int N = 101010;
    
    // Geometry
    const db eps = 1e-8;
    int sgn(db x){return (x > eps) - (x < -eps);}
    typedef complex<db> P;
    db dot(P a,P b){return (conj(a)*b).real();}
    db cross(P a,P b){return (conj(a)*b).imag();}
    
    // Matrix
    typedef vector<vi> MM;
    MM operator * (const MM a,const MM b){
        int L = sz(a);MM r(L,vi(L,0));
        rep(i,0,L) r[i][i] = 0;
        rep(i,0,L) rep(j,0,L) rep(k,0,L) r[i][j] += a[i][k] * b[k][j];
        return r;
    }
    MM operator ^ (MM a,ll t){
        MM r(sz(a),vi(sz(a),0));
        rep(i,0,sz(a)) r[i][i] = 1;
        for(;t;t>>=1,a=a*a) if(t&1) r=r*a;
        return r;
    }
    
    // Plus
    const int MOD = 1e9 + 7;
    void pp(int &x,int d){
        x += d;if(x >= MOD) x -= MOD;
    }
    // pp(a , P - x);
    
    // treeDP
    vi g[N];
    int sz[N];
    void dfs(int c,int pa){
        sz[c] = 1;
        for(auto t : g[c]) if(t != pa){ // c++11
            dfs(t , c);
            sz[c] += sz[t];
        }
    }
    
    // dsu
    int fa[N];
    int F(int x){return fa[x] == x ? x : fa[x] = F(fa[x]);}
    void M(int x,int y){fa[F(x)]=F(y);}
    
    // 两倍空间的线段树
    #define id(l,r) (l+r)|(l!=r)
    #define pr int c=id(l,r),m=(l+r)>>1
    int sum[N<<1];
    int Build(int l,int r){pr;
        if(l == r) return sum[c] = 1;
        else return sum[c] = Build(l,m) + Build(m+1,r);
    }
    
    int main(){
        int u = 0, v = 1;
        std::swap(u , v); // swap
    
        int a[20] , n = 20;
        cout << *std::max_element(a , a + n) << endl;// [a , a+n)
        cout << *std::min_element(a , a + n) << endl;
    
        vi V;// about 10 int
        sort(all(V));V.erase(unique(all(V),V.end())); // 离散化
    #define Rk(x) lower_bound(all(V) , x) - V.begin() + 1
    
        for(int i=0,j=0;i<sz(V);i=j){ // 相同值处理
            for(j=i;j<sz(V)&&V[j]==V[i];++j);
            // Cal(i , j) //[i , j)
        }
    
        int g[10][10] , m = 10;
        rep(i,0,n) rep(j,0,m) scanf("%d",&g[i][j]); // 同逻辑共行
    
    #define lb(x) (x&-(x))
        int cnt[1<<6];
        rep(i,1,1<<6) cnt[i] = cnt[i^lb(i)] + 1; // __builtin_popcount();
    
        sort(all(V),[&](int a,int b){return cnt[a]<cnt[b];}); // c++11
    
        rep(mask,0,1<<10) // 枚举子集
            for(int j=mask;j;j=(j-1)&mask)
                ;// Cal
    
        int f[1<<10];
        rep(i,0,10) rep(j,0,1<<10) if(j>>i&1) pp(f[j],f[j^(1<<i)]); // 高维前缀和
    
        vector<pii> p; // pair 排序
        rep(i,0,20) p.pb(mp(rand(),i));
        sort(all(p));
    
        rep(i,0,7) a[i] = i; // 枚举排列
        do{
            // Cal;
        }while(next_permutation(a , a + 7));
    
        fill(a , a + 20 , 0);// any number
    
        int &r=f[10];// 善用引用
        rep(i,0,10) r+=i;
    
        int C[10][10] = {{1}};// 适当的三目运算符
        rep(i,1,10) rep(j,0,i+1) C[i][j] = j ? (C[i-1][j-1] + C[i-1][j]) : 1;
    
        return 0;
    }
  • 相关阅读:
    阿衣楚往事
    加速计算机启动
    此一生,与谁相逢v
    关于cmd代码
    关于POJO
    ERP,SOA与J2EE什么关系
    QoBean技术文档(1):QoBean的基础技术
    ed 1.7 支持60种编程语言的免费编辑器
    面试必问的16个经典问题的回答思路
    Java 多线程间的通讯
  • 原文地址:https://www.cnblogs.com/klaycf/p/9798467.html
Copyright © 2011-2022 走看看