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",n-1);
    }
}

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;
}

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\n",dfs(0,n));
        //cout << ct << endl;
    }
    return 0;
}

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;
}

原文地址:https://www.cnblogs.com/solvit/p/9651897.html

时间: 2024-10-06 22:00:21

ACM-ICPC 2018 南京赛区网络预赛的相关文章

ACM-ICPC 2018 南京赛区网络预赛 E题

ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest with n (0 < n \le 20)n(0<n≤20) problems. And he knows the answer of all of these problems. However, he can submit ii-th problem if and only if he has s

ACM-ICPC 2018 南京赛区网络预赛 Lpl and Energy-saving Lamps 线段树

目录 ACM-ICPC 2018 南京赛区网络预赛 Lpl and Energy-saving Lamps 线段树 题面 题意 思路 ACM-ICPC 2018 南京赛区网络预赛 Lpl and Energy-saving Lamps 线段树 题面 During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Dragon imprisoned Lpl in the

ACM-ICPC 2018 南京赛区网络预赛 J.Sum

Sum A square-free integer is an integer which is indivisible by any square number except 11. For example, 6 = 2 \cdot 36=2⋅3 is square-free, but 12 = 2^2 \cdot 312=22⋅3 is not, because 2^222 is a square number. Some integers could be decomposed into

ACM-ICPC 2018 南京赛区网络预赛 L. Magical Girl Haze

262144K There are NN cities in the country, and MM directional roads from uu to v(1\le u, v\le n)v(1≤u,v≤n). Every road has a distance c_ici?. Haze is a Magical Girl that lives in City 11, she can choose no more than KK roads and make their distances

计蒜客 ACM-ICPC 2018 南京赛区网络预赛 A. An Olympian Math Problem-数学公式题

A. An Olympian Math Problem 54.28% 1000ms 65536K Alice, a student of grade 66, is thinking about an Olympian Math problem, but she feels so despair that she cries. And her classmate, Bob, has no idea about the problem. Thus he wants you to help him.

线性素数筛 ACM-ICPC 2018 南京赛区网络预赛 J Sum

https://www.jisuanke.com/contest/1555?view=challenges 题意: 题解:写完都没发现是个积性函数233 想法就是对x分解质因数,f(x)就是2^k,其中k是x分解结果中次数为一的质因子个数.如果有某个次数大于等于3,f(x)==0; 这样明显会TLE 所以就想一个递推的方法. 于是魔改了一下线性筛. #include<iostream> #include<cstdlib> #include<cstdio> #includ

ACM-ICPC 2018 南京赛区网络预赛 - C GDY (模拟)

诶,比赛时差一点就debug出来了 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int mod = 14; map<int,int> vz[205]; LL ans[205]; int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); freopen("out.tx

ACM-ICPC 2018 南京赛区网络预赛 做题记录

比赛的时候被J题卡常然后B题自闭最后G题没调完 5题gg 现在补题进度:6/12 A. 题解: 高考数学题,裂项完之后答案就是n!-1 (n!)%n=0,所以就是n-1 1 #include<bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 int T; 5 ll n; 6 int main() 7 { 8 cin>>T; 9 while(T--) 10 { 11 cin>>n; 12 cout

ACM-ICPC 2018 南京赛区网络预赛 K. The Great Nim Game

题意:有N堆石子(N为大数),每堆的个数按一定方式生成,问先手取若干堆进行尼姆博弈,必胜的方式有多少种. 题解:因为 k < 4096,所以出现的数最多只有4096个,对每个数字只考虑出现奇/偶次进行dp,答案是所有不等于0的dp值的和.然后如果一个数字出现x次,它对自己出现奇数次的方案数和偶数次的方案数贡献都是乘上2 ^ (x - 1),每个数字的贡献都是2 ^ (x - 1) 总贡献就是2 ^ (N - ∑(vis[i])).大数可以一边读入一边取模. 1 #include <bits/s

ACM-ICPC 2018 南京赛区网络预赛 G Lpl and Energy-saving Lamps(模拟+线段树)

https://nanti.jisuanke.com/t/30996 题意 每天增加m个灯泡,n个房间,能一次性换就换,模拟换灯泡过程.询问第几天的状态 分析 离线做,按题意模拟.比赛时线段树写挫了..导致不断超时,我太弱了.每次询问符合要求的最左边的点. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #i