• ACM-ICPC 2018 南京赛区网络预赛


    A An Olympian Math Problem 

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    ll T,n;
    int main(){
        scanf("%lld",&T);
        while(T--){
            scanf("%lld",&n);
            printf("%lld
    ",n-1);
        }
    }
    View Code

    B The writing on the wall

    C GDY

    D Jerome's House

    E AC Challenge

    #include <bits/stdc++.h>
    using namespace std;
    long long a[25],b[25];
    long long dis[2000005];
    int vis[2000005];
    int pre[25];
    int sta[25];
    int main()
    {
            memset(sta,0,sizeof(sta));
            memset(dis,0,sizeof(dis));
            memset(vis,0,sizeof(vis));
            int n;
            scanf("%d",&n);
            
            for(int i = 0;i < n;++i){
                scanf("%lld%lld%d",&a[i],&b[i],&pre[i]);
                int p;
                for(int j = 0;j < pre[i];++j){
                    scanf("%d",&p);
                    sta[i] |= (1<<(p-1));
                }
                //cout << sta[i] << endl;
            }
            int now = 0;
            queue<int> Q;
            while(!Q.empty()) Q.pop();
            Q.push(0);
            while(!Q.empty()){
                now = Q.front();
                Q.pop();
                vis[now] = 0;
                for(int i = 0;i < n;++i){
                    if((sta[i] & now) == sta[i] && ((1<<i) & now) == 0){
                        int nxt = now | (1<<i);
                        int cnt = 0;
                        for(int j = 0;j < n;++j) if((1<<j)&nxt) cnt++;
                        if(dis[nxt] < dis[now] + cnt*a[i] + b[i]){
                            dis[nxt] = dis[now] + cnt*a[i] + b[i];
                            if(!vis[nxt]) Q.push(nxt),vis[nxt] = 1;
                        }
                    }
                }
            }
            int up = (1<<n);
            long long ans = 0;
            for(int i = 0;i < up;++i) ans = max(ans,dis[i]);
            cout << ans << endl;
            return 0;
    }
    View Code

    F An Easy Problem On The Trees

    G Lpl and Energy-saving Lamps

    H Set

    I Skr

    J Sum

    #include <bits/stdc++.h>
    using namespace std;
    #define N 20000006
    int prime[N],tag[N];
    int get_prime(int n){
        int tot = 0;
        for(int i = 2;i <= n;++i){
            if(!tag[i]) prime[tot++] = i;
            for(int j = 0;j < tot && 1LL * prime[j] * i <= n;++j){
                tag[i * prime[j]] = 1;
                if(i % prime[j] == 0) break;
            }
        }
        return tot;
    }
    
    int cnt;
    int ct;
    int dfs(int now,int n){
        ct++;
        if(n == 0) return 0;
        if(now == cnt || prime[now] > n) return 1;
        if(prime[now]*prime[now] > n){
            int tmp = (upper_bound(prime,prime+cnt,n)-prime)-now;
            return tmp*2+1;
        }
        int ans = 0;
        ans += dfs(now+1,n/(1LL*prime[now]*prime[now]));
        ans += 2*dfs(now+1,n/prime[now]);
        ans += dfs(now+1,n);
        return ans;
    }
    
    
    int main()
    {
        cnt = get_prime(20000000);
        int T;
        scanf("%d",&T);
        while(T--){
            int n;
            scanf("%d",&n);
            ct = 0;
            printf("%d
    ",dfs(0,n));
            //cout << ct << endl;
        }
        return 0;
    }
    View Code

    K The Great Nim Game

    L Magical Girl Haze 

    #include <bits/stdc++.h>
    using namespace std;
    #define M 200005
    #define N 100005
    int head[N];
    bool vis[N][11];
    long long dis[N][11];
    int cnt;
    
    struct Edge{
        int to,next,l;
    }edge[M<<1];
    
    void ad(int u,int v,int c){
        edge[cnt].to = v,edge[cnt].next = head[u],edge[cnt].l = c,head[u] = cnt++;
    }
    struct Node{
        int p,tim;
        long long dis;
        bool operator < (const Node &a)const{
            return dis > a.dis;
        }
    };
    priority_queue<Node> Q;
    int main()
    {
        int T;
        scanf("%d",&T);
        while(T--){
            cnt = 0;
            memset(head,-1,sizeof(head));
            memset(dis,0x3f,sizeof(dis));
            memset(vis,0,sizeof(vis));
            int n,m,k;
            int u,v,c;
            scanf("%d%d%d",&n,&m,&k);
            for(int i = 1;i <= m;++i){
                scanf("%d%d%d",&u,&v,&c);
                ad(u,v,c);
            }
            dis[1][0] = 0;
            while(!Q.empty()) Q.pop();
            Node nd;
            nd.p = 1,nd.tim = 0,nd.dis = dis[1][0];
            Q.push(nd);
            long long l;
            while(!Q.empty()){
                nd = Q.top();
                Q.pop();
                int u = nd.p,tim = nd.tim;
                if (vis[u][tim]) continue;
                vis[u][tim] = 1;
                for(int i = head[u];i != -1;i = edge[i].next){
                    v = edge[i].to;
                    l = edge[i].l;
                    if(tim + 1 <= k){
                        if(!vis[v][tim+1] && dis[v][tim+1] > dis[u][tim]){
                            dis[v][tim+1] = dis[u][tim];
                            nd.p = v,nd.tim = tim+1,nd.dis = dis[v][tim+1];
                            Q.push(nd);
                        }
                    }
                    if(!vis[v][tim] && dis[v][tim] > dis[u][tim] + l){
                        dis[v][tim] = dis[u][tim] + l;
                        nd.p = v,nd.tim = tim,nd.dis = dis[v][tim];
                        Q.push(nd);
                    }
                }
            }
            long long ans = 0x3f3f3f3f3f3f3f3f;
            for(int i = 0;i <= k;++i) ans = min(ans,dis[n][i]);
            cout << ans << endl;
        }
        return 0;
    }
    View Code
  • 相关阅读:
    JS流程控制语句
    JS操作符
    JS数据类型
    JS基础语法与JS变量
    CSS案例1(导航栏)
    CSS三大特性
    CSS——背景,渐变和列表
    HTML+CSS项目——模拟京东网页
    JavaScript简介
    js -04课程 更换背景图片
  • 原文地址:https://www.cnblogs.com/solvit/p/9651897.html
Copyright © 2020-2023  润新知