ACM-ICPC 2018 徐州赛区网络预赛

Posted solvit

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

 

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

ACM-ICPC 2018 徐州赛区网络预赛 D. EasyMath

ACM-ICPC 2018 徐州赛区网络预赛 J Maze Designer

ACM-ICPC 2018 徐州赛区网络预赛(9.9)

ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer (最大生成树+LCA求节点距离)

ACM-ICPC 2018 徐州赛区网络预赛 A. Hard to prepare

ACM-ICPC 2018 徐州赛区网络预赛 B. BE, GE or NE