zoukankan      html  css  js  c++  java
  • ACM-ICPC 2018 徐州赛区网络预赛

    A Hard to prepare

    #include <bits/stdc++.h>
    using namespace std;
    #define N 1000005
    long long mod = 1e9 + 7;
    
    long long power(long long a,long long b){
        a %= mod;
        long long ret = 1;
        while(b){
            if(b & 1) ret = ret * a % mod;
            a = a * a % mod;
            b >>= 1;
        }
        return ret;
    }
    
    long long re[N],inv[N],fac[N];
    
    void init(int n){
        re[0] = inv[1] = fac[0] = 1;
        for(int i = 1;i <= n;++i) fac[i] = fac[i-1] * i % mod;
        for(int i = 2;i <= n;++i) inv[i] = (mod-mod/i)*inv[mod%i] % mod;
        for(int i = 1;i <= n;++i) re[i] = re[i-1] * inv[i] % mod;
    }
    
    long long c(int a,int b){
        if(a < b) return 0;
        return fac[a]*re[b]%mod*re[a-b]%mod;
    }
    
    int main()
    {
        init(1000000);
        int T;
        cin >> T;
        while(T--){
            long long k,n;
            scanf("%lld%lld",&n,&k);
            long long ans = 0;
            long long tot = power(2LL,k);
            long long pre = 1;
            for(int i = n-1;i >= 0;--i){
                pre = pre * tot % mod;
                ans += 1LL * ((i&1)?-1:1) * c(n,i) * pre % mod; 
                ans = (ans + mod) % mod;
            }
            printf("%lld
    ",(ans+(n&1?0:1)*tot)%mod);
        }
        return 0;
    }
    View Code

    B BE, GE or NE

    #include <bits/stdc++.h>
    using namespace std;
    int sta[210][1005];
    int a[1005],b[1005],c[1005];
    int main()
    {
        int n,m,l,r;
        scanf("%d%d%d%d",&n,&m,&r,&l);
        for(int i = 1;i <= n;++i){
            scanf("%d%d%d",&a[i],&b[i],&c[i]);
        }
        for(int i = -100;i <= 100;++i){
            if(i <= l) sta[i+100][n+1] = 1;//第二个人赢的位置
            else if(i <= r) sta[i+100][n+1] = 2;
            else sta[i+100][n+1] = 3;//第一个人赢
        }
        for(int i = n;i >= 1;--i){
            for(int j = -100;j <= 100;++j){
                if(i & 1){
                    sta[j+100][i] = 1;
                    //第一个人操作
                    if(a[i])
                        sta[j+100][i] = max(sta[min(j+100+a[i],200)][i+1],sta[j+100][i]);
                    if(b[i])
                        sta[j+100][i] = max(sta[max(0,j+100-b[i])][i+1],sta[j+100][i]);
                    if(c[i])
                        sta[j+100][i] = max(sta[-j+100][i+1],sta[j+100][i]);
                }
                else{
                    sta[j+100][i] = 3;
                    if(a[i])
                        sta[j+100][i] = min(sta[min(j+100+a[i],200)][i+1],sta[j+100][i]);
                    if(b[i])
                        sta[j+100][i] = min(sta[max(0,j+100-b[i])][i+1],sta[j+100][i]);
                    if(c[i])
                        sta[j+100][i] = min(sta[-j+100][i+1],sta[j+100][i]);
                }
            }
        }
        if(sta[m+100][1] == 1) puts("Bad Ending");
        else if(sta[m+100][1] == 2) puts("Normal Ending");
        else puts("Good Ending");
        return 0;
    }
    View Code

    C Cacti Lottery

    D Easy Math

    E End Fantasy VIX

    F Features Track 

    #include<bits/stdc++.h>
    
    using namespace std;
    typedef long long ll;
    map<pair<int,int>,int> M;
    map<pair<int,int>,int> vis;
    int t,n,k,a,b;
    int ans;
    int main()
    {
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            vis.clear();M.clear();
            ans = 1;
            for(int i=1;i<=n;i++)
            {
                scanf("%d",&k);
                for(int j=0;j<k;j++){
                    scanf("%d%d",&a,&b);
                    if(vis[make_pair(a,b)] == i-1){
                        M[make_pair(a,b)]++;
                        ans = max(M[make_pair(a,b)],ans);
                    }
                    else if(vis[make_pair(a,b)] == i){
                        continue;
                    }
                    else{
                        M[make_pair(a,b)] = 1;
                    }
                    vis[make_pair(a,b)] = i;
                }
            }
            cout<<ans<<endl;
        }
    
        return 0;
    }
    View Code

    G Trace

    #include<bits/stdc++.h>
    
    using namespace std;
    typedef long long ll;
    struct point{
        int x,y;
        bool operator < (const point & _point)const{
            return x < _point.x;
        }
    }tot[50005];
    set<point> M;
    int n,a,b;
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",&tot[i].x,&tot[i].y);
    
        }
        M.clear();
        ll ans = 0;
        ans += tot[n].x;ans += tot[n].y;
        M.insert(tot[n]);
        //cout<<ans<<endl;
    
        for(int i=n-1;i>=1;i--)
        {
            if(M.lower_bound(tot[i])==M.end()){
                set<point>::iterator it = M.end();
                it--;
                point temp = *(it);
                ans += tot[i].y;
                ans += tot[i].x - temp.x;
               // cout<<"11111111 "<<temp.x<<" "<<temp.y<<endl;
            }
            else if(M.lower_bound(tot[i])==M.begin()){
                point temp = *M.begin();
                ans += tot[i].x;
                ans += tot[i].y - temp.y;
                //cout<<"22222222 "<<temp.x<<" "<<temp.y<<endl;
            }
            else{
                set<point>::iterator it = (M.lower_bound(tot[i]));
                point temp1 = *it;
                it--;
                point temp = *it;
                ans += tot[i].y - temp1.y;
                ans += tot[i].x - temp.x;
                //cout<<"13333331 "<<temp.x<<" "<<temp.y<<endl;
               // cout<<"14444444 "<<temp1.x<<" "<<temp1.y<<endl;
            }
            M.insert(tot[i]);
           // cout<<ans<<endl;
        }
        cout<<ans<<endl;
    }
    View Code

    H Ryuji doesn't want to study 

    #include <bits/stdc++.h>
    using namespace std;
    #define N 100005
    #define lc (d<<1)
    #define rc (d<<1|1)
    #define mid ((l+r)>>1)
    long long v[N];
    struct Tr{
        long long sum,dp,cnt;
        Tr operator + (const Tr A) const{
            Tr B;
            B.cnt = A.cnt + cnt;
            B.sum = A.sum + sum;
            B.dp = A.dp + sum * A.cnt + dp;
            return B;
        }
    }tr[N<<2];
    
    void build(int l,int r,int d){
        if(l == r){
            tr[d].cnt = 1;
            tr[d].dp = tr[d].sum = v[l];
            return;
        }
        build(l,mid,lc),build(mid+1,r,rc);
        tr[d] = tr[lc] + tr[rc];
    }
    
    void update(int l,int r,int pos,int val,int d){
        if(l == r){
            tr[d].sum = tr[d].dp = val;
            return;
        }
        if(pos <= mid) update(l,mid,pos,val,lc);
        else update(mid+1,r,pos,val,rc);
        tr[d] = tr[lc] + tr[rc];
    }
    
    Tr query(int l,int r,int L,int R,int d){
        if(L == l && R == r) return tr[d];
        if(R <= mid) return query(l,mid,L,R,lc);
        if(L > mid) return query(mid+1,r,L,R,rc);
        return query(l,mid,L,mid,lc) + query(mid+1,r,mid+1,R,rc);
    }
    
    int main()
    {
        int n,q;
        cin >> n >> q;
        for(int i = 1;i <= n;++i) scanf("%lld",&v[i]);
        build(1,n,1);
        int op,L,R;
        for(int i = 1;i <= q;++i){
            scanf("%d%d%d",&op,&L,&R);
            if(op == 1) printf("%lld
    ",query(1,n,L,R,1).dp);
            else update(1,n,L,R,1);
        }
        
        return 0;
    }
    View Code

    I Characters with Hash

    #include <bits/stdc++.h>
    using namespace std;
    int T,n;
    char s[1000005],z;
    int main(){
        scanf("%d",&T);
        while(T--){
            scanf("%d %c",&n,&z);
            scanf("%s",s);
            int ans = strlen(s) * 2;
            for (int i = 0;i < strlen(s);++i){
                int tmp = abs(s[i] - z);
                //cout << tmp << endl;
                if (tmp == 0) ans -= 2;
                else if (tmp < 10 && tmp > 0){
                    ans--;
                    break;
                }else if (tmp >= 10) break;
            }
            if (ans == 0) puts("1");
            else printf("%d
    ",ans);
        }
    }
    View Code

    J Maze Designer

    K Morgana Net

  • 相关阅读:
    Spark学习之路 九、SparkCore的调优之数据倾斜调优
    Spark学习之路 八、SparkCore的调优之开发调优
    Spark Core、Spark Sql、Spark Streaming 联系与区别
    Spark学习之路 七、Spark 运行流程
    Spark学习之路 六、Spark Transformation和Action
    Spark学习之路 五、Spark伪分布式安装
    一起来学习Shell脚本
    简单整理React的Context API
    阅读别人项目源码时的随手记(乱七八糟待归类整理)
    React.Component 与 React.PureComponent(React之性能优化)
  • 原文地址:https://www.cnblogs.com/solvit/p/9651776.html
Copyright © 2011-2022 走看看