2019 Multi-University Training Contest 1

1001.Blank

题意

1002 Operation(前缀线性基)

原题

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+50;
int pos[maxn][32];
int val[maxn][32];

void add(int x,int ans){
    for(int i=0;i<=31;i++){
        pos[x][i]=pos[x-1][i];
        val[x][i]=val[x-1][i];
    }
    int tmp=x;
    for(int i=31;i>=0;i--){
        if(ans&(1<<i)){
            if(val[x][i]==0){
                val[x][i]=ans;
                pos[x][i]=tmp;
                break;
            }
            if(pos[x][i]<tmp){
                swap(pos[x][i],tmp),swap(val[x][i],ans);
            }
            ans^=(val[x][i]);
        }
    }
}

int main(){
    int t;
    std::ios::sync_with_stdio(false);
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++){
            int a;
            cin>>a;
            add(i,a);
        }
        int last=0;
        while(m--){
            int op;
            cin>>op;
            if(op){
                n++;
                int x;
                cin>>x;
                x^=last;
                add(n,x);
            }
            else{
                int l,r;cin>>l>>r;
                l=(l^last)%n+1;
                r=(r^last)%n+1;
                if(l>r)swap(l,r);
                int ans=0;
                for(int i=31;i>=0;i--){
                    if(pos[r][i]>=l&&((ans^val[r][i])>ans))ans=ans^val[r][i];
                }
                cout<<ans<<endl;
                last=ans;
            }
        }
    }
    return 0;
}

1003.Milk

1004.Vacation(二分答案)

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e6+50;
const double eps=1e-7;
int l[maxn],s[maxn],v[maxn],n;
double pos[maxn];

bool check(double mid){
    pos[n+1]=mid*v[n+1]-s[n+1]-l[n+1];
    for(int i=n;i;i--){
        if(mid*v[i]-s[i]>=pos[i+1])
            pos[i]=pos[i+1]-l[i];
        else pos[i]=mid*v[i]-s[i]-l[i];
    }
    return pos[1]+l[1]>=eps;
}

int main(){
    std::ios::sync_with_stdio(false);
    while(cin>>n){
        for(int i=1;i<=n+1;i++)cin>>l[i];
        for(int i=1;i<=n+1;i++)cin>>s[i];
        for(int i=1;i<=n+1;i++)cin>>v[i];
        double l=0.0,r=1e9,ans;
        while(l+eps<=r){
            double mid=(l+r)/2.0;
            if(check(mid)){
                r=mid;
                ans=mid;
            }
            else l=mid;
        }
        cout<<fixed<<setprecision(10)<<ans<<endl;
    }
    return 0;
}

1005.Path(网络流+最短路)

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+50;
typedef long long ll;
ll S,T,From[maxn],Laxt[maxn],Next[maxn],To[maxn],Cap[maxn],cnt;
ll vd[maxn],dis[maxn];
void add(int u,int v,ll c){
    Next[++cnt]=Laxt[u];Laxt[u]=cnt;To[cnt]=v;Cap[cnt]=c;From[cnt]=u;
    Next[++cnt]=Laxt[v];Laxt[v]=cnt;To[cnt]=u;Cap[cnt]=0;From[cnt]=v;
}
ll sap(int u,ll flow,ll limit){
    if(u==T||flow==0)return flow;
    int tmp,delta=0;
    for(int i=Laxt[u];i;i=Next[i]){
        int v=To[i];
        if(dis[u]==dis[v]+1&&Cap[i]){
            tmp=sap(v,min(flow-delta,Cap[i]),limit);
            Cap[i]-=tmp;Cap[i^1]+=tmp;delta+=tmp;
            if(dis[S]>=(limit)||delta==flow)return delta;
        }
    }
    vd[dis[u]]--;if(!vd[dis[u]])dis[S]=limit;
    vd[++dis[u]]++;
    return delta;
}
void init(int limit){
    cnt=1;
    for(int i=0;i<=limit;i++)Laxt[i]=dis[i]=vd[i]=0;
}
ll dist1[maxn];
ll dist2[maxn];
ll a[maxn],b[maxn],c[maxn];
struct node{
    int u,v;
    ll w;
};
struct no{
    int id;
    ll w;
    bool operator <(const no &a)const{
        return this->w>a.w;
    }
};
vector<node>G[maxn];
void dij(ll d[],int n,int S){
    for(int i=1;i<=n;i++)d[i]=1e18;
    d[S]=0;
    priority_queue<no>Q;
    Q.push({S,d[S]});
    while(!Q.empty()){
        no tmp=Q.top();
        Q.pop();
        int u=tmp.id;
        for(int i=0;i<G[u].size();i++){
            node k=G[u][i];
            int v=k.v,w=k.w;
            if(d[v]>d[u]+w){
                d[v]=d[u]+w;
                Q.push({v,d[v]});
            }
        }
    }
}

int main(){
    std::ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        init(n+2);
        for(int i=1;i<=n;i++)G[i].clear();
        for(int i=1;i<=m;i++){
            cin>>a[i]>>b[i]>>c[i];
            G[a[i]].push_back({a[i],b[i],c[i]});
        }
        S=1;T=n;
        dij(dist1,n,S);
        for(int i=1;i<=n;i++)G[i].clear();
        for(int i=1;i<=m;i++){
            G[b[i]].push_back({b[i],a[i],c[i]});
        }
        dij(dist2,n,T);
        for(int i=1;i<=m;i++){
            if(a[i]!=b[i]&&dist1[a[i]]+c[i]+dist2[b[i]]==dist1[T]){
                add(a[i],b[i],c[i]);
            }
        }
        ll ans=0;
        while(dis[S]<n+2){
            ans+=sap(S,1e18,n+2);
        }
        cout<<ans<<endl;
    }
    return 0;
}

1006Typewriter

1007Meteor

1008Desert

1009String

1010Kingdom

1011Function

1012.Sequence

1013. Code

posted @ 2019-07-22 20:36  luowentao  阅读(885)  评论(0编辑  收藏  举报