zoukankan      html  css  js  c++  java
  • trick

    priority_queue<int>que//默认最大的先出来 
    priority_queue<int,vector<int>,greater<int> >que;///最小的先出来 
    struct node{
        int x,y;
        bool operator < (const node &b)const{
            return x<b.x;///大的先出来 
        }
    }x1,x2,x3;
    y=floor(x)//(向下取整)
    y=ceil(x)//(向上取整)
    

     排序部分

    sort(a,a+n)///快排,不稳定
    stable_sort(a,a+n)///归并排序,稳定。有时sort T了 可以用
    

     定义n*m向量数组

    int n,m;
    scanf("%d%d",&n,&m);
    vector<vector<int> >vv(n,vector<int>(m));

     输出int128

    #include <bits/stdc++.h>
    using namespace std;
    inline __int128 read(){
        __int128 x=0,f=1;
        char ch=getchar();
        while(ch<'0'||ch>'9'){
            if(ch=='-')
                f=-1;
            ch=getchar();
        }
        while(ch>='0'&&ch<='9'){
            x=x*10+ch-'0';
            ch=getchar();
        }
        return x*f;
    }
    
    inline void print(__int128 x){
        if(x<0){
            putchar('-');
            x=-x;
        }
        if(x>9)
            print(x/10);
        putchar(x%10+'0');
    }
    
    int main(void){
        __int128 a = read();
        __int128 b = read();
        __int128 m =read();
        print((a + b)%m);
        cout<<endl;
        return 0;
    }
    View Code

     取模的组合数:

    ll ksm(ll x,ll y,ll p){
        ll res=1ll;
        while(y){
            if(y&1)
                res=res*x%p;
            y>>=1;
            x=x*x%p;
        }
        return res;
    }
    struct CC{
        static const int N=300010;
        ll fac[N],inv[N];
        CC(){
            fac[0]=1;
            for(int i=1;i<N;i++)
                fac[i]=fac[i-1]*i%mod;
            inv[N-1]=ksm(fac[N-1],mod-2,mod);
            for(int i=N-1;i>=1;i--)
                inv[i-1]=inv[i]*i%mod;
        }
        ll operator()(ll a,ll b){ ///a>=b
            if(a<b || b<0)return 0;
            return fac[a]*inv[a-b]%mod*inv[b]%mod;
        }
        ll A(ll a,ll b){ ///a>=b
            if(a<b || b<0)return 0;
            return fac[a]*inv[a-b]%mod;
        }
    }C;
    int main(){
        ///直接C(n,m);//n>=m
    }
    View Code

     求“短”的subsequence(非连续)在原串出现次数(含问号,全能字符),复杂度:O(nm)(https://codeforces.com/contest/1426/problem/F

    #include<bits/stdc++.h>
    using namespace std;
    #define pb push_back
    #define MP make_pair
    #define lson root<<1,l,midd
    #define rson root<<1|1,midd+1,r
    typedef long long ll;
    const int mod=1e9+7;
    const int M=2e6+6;
    const int inf=0x3f3f3f3f;
    const ll INF=1e18;
    char s[M];
    ll f[10];
    int main(){
        int n;
        scanf("%d%s",&n,s+1);
        f[0]=1ll;
        f[1]=f[2]=f[3]=0;
        for(int i = 1; i <= n; i++){
    
            if(s[i]=='?'){
                f[3]=(f[3]*3ll+f[2])%mod;
                f[2]=(f[2]*3ll+f[1])%mod;
                f[1]=(f[1]*3ll+f[0])%mod;
                f[0]=(f[0]*3ll)%mod;
    
    
    
            }
            else f[s[i]-'a'+1] = (f[s[i]-'a'+1]+f[s[i]-'a'])%mod;
    
        }
        printf("%lld
    ",f[3]);
        return 0;
    }
    View Code

     求1~n的前缀和的前缀和:

            ans = n * n * (n + 1) / 2;///把每一个前缀和看作到n的前缀和,总共有n个;
     
            ans -= n * (n + 1) * (2 * n + 1) / 6;///列出来发现可以把上一项减去1^2+2^2+3^2+4^2……n^2=n * (n + 1) * (2 * n + 1) / 6 再加上1~n的前缀和
     
            ans += n * (n + 1) / 2;
    View Code

     set去最后一个值,定义时依照制定的来排序:

    ///依照dfs序来排序
    struct cmp{
        bool operator() (const int &x,const int &y)const{
            return dfn[x]<dfn[y];
        }
    };
    set<int,cmp>st[M];
    ///
    cout<<ser.rbegin()<<endl;
    View Code
  • 相关阅读:
    POJ_1523 SPF (Tarjan 求割点)
    POJ 3177&& 3352
    POJ 基础数据结构
    Bellman Ford, SPFA 学习笔记(含有负权的单源最短路径)
    HDU_3062 Party (2SAT)
    POJ二分图最大匹配的简单题目
    POJ 2553 The Bottom of a Graph (Trajan 强连通分量 缩点)
    POJ_3678 Katu Puzzle (2SAT)
    HDU_3836 Equivalent Set (Trajan 强连通分量 缩点)
    POJ1904 King's Quest(Tarjan 求缩点)
  • 原文地址:https://www.cnblogs.com/starve/p/11450456.html
Copyright © 2011-2022 走看看