ACM-ICPC 2018 沈阳赛区网络预赛

Posted solvit

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ACM-ICPC 2018 沈阳赛区网络预赛相关的知识,希望对你有一定的参考价值。

A Gudako and Ritsuka

 

B Call of Accepted

 

C Convex Hull

 

D Made In Heaven

技术分享图片
#include <bits/stdc++.h>
using namespace std;
const int MM = 1e5+5;
const int INF = 1e9+7;
int dis[MM];
int n, m;
int s, t, k;
int x, len, cnt[MM];
struct node{
    int v, dis;
};
vector <node> MMap[MM];
vector <node> reMMap[MM];
queue <int> q;
int T;
int a, b, l;
node p;

struct Edge{
    int v, w;
    friend bool operator < (Edge a, Edge b){
        return (a.w + dis[a.v]) > (b.w + dis[b.v]);
    }
};


void spfa(int s)
{
    bool vis[MM];
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < MM; ++i)
        dis[i] = INF;
    dis[s] = 0; vis[s] = true;
    while(!q.empty()) q.pop();
    q.push(s);
    while (!q.empty()){
        int u = q.front();
        q.pop();
        vis[u] = false;
        for (int i = 0; i < reMMap[u].size(); ++i){
            int v = reMMap[u][i].v,w = reMMap[u][i].dis;
            if (dis[v] > dis[u] + w){
                dis[v] = dis[u] + w;
                if (!vis[v]){
                    q.push(v);
                    vis[v] = true;
                }
            }
        }
    }
}

int a_star(int s,int t){
    Edge node1, node2;
    if (s == t) k++;
    if (dis[s] == INF) return -1;
    priority_queue <Edge> q;
    memset(cnt, 0, sizeof(cnt));
    node1.w = 0,node1.v = s;
    q.push(node1);
    while (!q.empty()){
        node2 = q.top();
        q.pop();
        len = node2.w;
        x = node2.v,cnt[x]++;
        if (cnt[t] == k) return len;
        if (cnt[x] > k) continue;
        int siz = MMap[node2.v].size();
        for (int i = 0; i < siz; ++i)
        {
            node1.v = MMap[node2.v][i].v;
            node1.w = len + MMap[node2.v][i].dis;
            q.push(node1);
        }
    }
    return -1;
}

int main(){
    while (~scanf("%d%d", &n, &m)){
        scanf("%d%d%d%d", &s, &t, &k,&T);
        for (int i = 0; i < MM; ++i)
            MMap[i].clear();
        for (int i = 0; i < MM; ++i)
            reMMap[i].clear();
        for (int i = 1; i <= m; ++i){
            scanf("%d%d%d", &a, &b, &l);
            p.v = b;
            p.dis = l;
            MMap[a].push_back(p);
            p.v = a;
            reMMap[b].push_back(p);
        }
        spfa(t);
        int tmp = a_star(s,t); 
        if (tmp == -1) {
            puts("Whitesnake!");continue;
        }
        if (a_star(s,t) <= T) puts("yareyaredawa");
            else puts("Whitesnake!");
    }
}
View Code

E The cake is a lie

 

F Fantastic Graph 

技术分享图片
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 2005;
int M[maxn][maxn];
int tx[maxn],ty[maxn];
int n,m,k,l,r,u,v;

int main()
{
    int cas = 1;
    while(~scanf("%d%d%d",&n,&m,&k))
    {
        memset(M,0,sizeof(M));
        scanf("%d%d",&l,&r);
        for(int i=0;i<k;i++)
        {
            scanf("%d%d",&u,&v);
            M[u][v]++;
        }
        int f = 1;
        for(int i=1;i<=n;i++){
            int temp = 0;
            for(int j=1;j<=m;j++){
                temp += M[i][j];
            }
            tx[i] = temp;
            if(temp<l)f=0;
        }
        for(int i=1;i<=m;i++){
            int temp = 0;
            for(int j=1;j<=n;j++){
                temp += M[j][i];
            }
            ty[i] = temp;
            if(temp<l)f=0;
        }
        if(f==0){
            printf("Case %d: No
",cas++);continue;
        }
        for(int i=1;i<=n;i++)
        {
            if(tx[i] > r)
            {
                int tt = tx[i] - r;
                for(int j=1;j<=m;j++){
                    int mi = min(tt,min(M[i][j],ty[j]-r));
                    tt -= mi;M[i][j] -= mi;ty[j] -= mi;
                    if(tt == 0)break;
                }
                if(tt > 0){
                    for(int j=1;j<=m;j++){
                        int mi = min(tt,min(M[i][j],ty[j]-l));
                        tt -= mi;M[i][j] -= mi;ty[j] -= mi;
                        if(tt == 0)break;
                    }
                }
                if(tt > 0){
                    f = 0;break;
                }
            }
        }
        if(f){
            printf("Case %d: Yes
",cas++);
        }
        else{
            printf("Case %d: No
",cas++);
        }
    }
    return 0;
}
View Code

G Spare Tire

技术分享图片
#include <bits/stdc++.h>
using namespace std;
#define N 100000005
long long inv6 = 166666668;
long long inv2 = 500000004;
long long mod = 1e9+7;
int p[20];
int main()
{   int n,m;
    while(~scanf("%d%d",&n,&m)){
        int cnt = 0;
        for(int i = 2;i*i <= m;++i){
            if(m % i == 0){
                p[cnt++] = i;
                while(m%i == 0) m /= i;
            }
        }
        
        if(m != 1) p[cnt++] = m;
        int up = (1<<cnt);
        long long ans = 0;
        for(int i = 0;i < up;++i){
            int tmp = 1;
            int kk = 0;
            for(int j = 0;j < cnt;++j){
                if((i>>j)&1) kk++,tmp *= p[j];
            }
            long long num = n/tmp;
            long long now = 1LL*tmp*tmp%mod*(num*2+1)%mod*(num+1)%mod*num%mod*inv6%mod;
            now = (now + 1LL* tmp * (1+num) % mod * num % mod * inv2 % mod) % mod;
            ans = (ans + now*(kk&1 ? -1 : 1) + mod) % mod;
        }
        printf("%lld
",ans);
    }
    return 0;
}
View Code

H Hamming Weight

 

I Lattice‘s basics in digital electronics

技术分享图片
#include <bits/stdc++.h>
using namespace std;
char s[20];
int mp[60000];
char str[200005];
bool code[1000006],nxt[1000005];

int main()
{
    int T;
    cin >> T;
    while(T--){
        memset(mp,0,sizeof(mp));
        int m,n;
        scanf("%d%d",&m,&n);
        int v;
        for(int i = 1;i <= n;++i){
            scanf("%d%s",&v,s);
            int len = strlen(s);
            int tmp = 0;
            for(int j = 0;j < len;++j){
                tmp *= 3;
                tmp += s[j]-0+1;
            }
            mp[tmp] = v;
        }
        scanf("%s",str);
        int len = strlen(str);
        int now = 0;
        for(int i = 0;i < len;++i){
            now += 4;
            int kk;
            if(str[i] >= 0 && str[i] <= 9)
                kk = str[i] - 0;
            else
                kk = str[i] - a + 10;
            for(int j = 1;j <= 4;++j){
                code[now-j] = (kk & 1);
                kk >>= 1;
            }
        }
        int cnt;
        int tot = 0;
        for(int i = 0;i <= now;i+=9){
            cnt = 0;
            for(int j = i;j < i+8;++j){
                if(code[j]) cnt++;
            }
            if(((cnt&1) && code[i+8] == 0) || ((cnt&1) == 0 && code[i+8])){
                for(int j = i;j < i+8;++j){
                    nxt[tot++] = code[j];
                }
            }
        }
        int tmp = 0;
        cnt = 0;
        for(int i = 0;i < tot;++i){
            if(cnt == m) break;
            tmp *= 3;
            tmp += nxt[i]+1;
            if(mp[tmp]){
                cnt++;
                printf("%c",mp[tmp]);
                tmp = 0;
            }
        }
        puts("");
    }
    return 0;
}
View Code

J Ka Chang

 

K Supreme Number 

技术分享图片
#include <bits/stdc++.h>
using namespace std;

int ans[20] = {1,2,3,5,7,11,13,17,23,31,37,53,71,73,113,131,137,173,311,317};
char s[1005];
int main()
{
    int T;
    cin >> T;
    cin.ignore();
    int ii = 1;
    while(T--){
        printf("Case #%d: ",ii++);
        gets(s);
        int len = strlen(s);
        if(len >= 4) puts("317");
        else{
            int tmp = 0;
            for(int i = 0;i < len;++i){
                tmp *= 10;
                tmp += s[i]-0;
            }
            for(int i = 19;i >= 0;--i){
                if(ans[i] <= tmp){
                    printf("%d
",ans[i]);
                    break;
                }
            }
        }
    }
    return 0;
}
View Code

 

以上是关于ACM-ICPC 2018 沈阳赛区网络预赛的主要内容,如果未能解决你的问题,请参考以下文章

ACM-ICPC 2018 沈阳赛区网络预赛

ACM-ICPC 2018 沈阳赛区网络预赛

ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph

ACM-ICPC 2018 沈阳赛区网络预赛 KSupreme Number

ACM-ICPC 2018 沈阳赛区网络预赛 DMade In Heaven

ACM-ICPC 2018 沈阳赛区网络预赛 K. Supreme Number