zoukankan      html  css  js  c++  java
  • The Preliminary Contest for ICPC Asia Xuzhou 2019

    B题:https://nanti.jisuanke.com/t/41384

    题意:俩操作,1操作:讲位置为x视为无效。2操作:询问以x位置为起点向后最近的有效位置。(起初全都有效)

    分析:离散化+并查集,当一个位置无效时,2操作对他的询问就变成他的祖先,即找最近有效(找祖先)

    #include<bits/stdc++.h>
    using namespace std;
    const int M=1e6+6;
    int tot,f[M<<2],lisan[M<<2],op[M],val[M];
    int find(int x){
        return x==f[x]?x:f[x]=find(f[x]);
    }
    int main(){
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=m;i++){
            scanf("%d%d",&op[i],&val[i]);
            lisan[++tot]=val[i];//保证离散化后相邻之间仍具有相邻性 
            lisan[++tot]=val[i]+1;
        }
        sort(lisan+1,lisan+1+tot);
        tot=unique(lisan+1,lisan+1+tot)-(lisan+1);
        for(int i=0;i<=tot;i++)
            f[i]=i;
        for(int i=1;i<=m;i++){
            if(op[i]==1){
                int fu=lower_bound(lisan+1,lisan+1+tot,val[i])-(lisan);
                int fv=lower_bound(lisan+1,lisan+1+tot,val[i]+1)-(lisan);
                f[find(fu)]=find(fv);
            }
            else{
                int fu=lower_bound(lisan+1,lisan+1+tot,val[i])-(lisan);
                int t=find(fu);
                if(lisan[t]>n)
                    puts("-1");
                else
                    printf("%d
    ",lisan[t]);
            }
        }
        return 0;
    }
    View Code

    K题:https://nanti.jisuanke.com/t/41393

    题意:在二维坐标内给定一些点,设点P为(Xc,Yc),对于每一个坐标要求一定要有和其他坐标(包括他自己)连线的中心点为P,若没有就添加上去,问最小添加次数(点P由能达到最小的方向去定,且点P在这个坐标内存不存在无所谓)

    分析:找每每俩个点配对形成的中心点数方案数,对于每一个方案点P唯一,然后求那个方案含有的点多,那么答案就是n-(这个方案含有的点数)

       细节:可能有重复的点,若要添加,就只要1和就行,所以事先经行去重后面好操作

    #include<bits/stdc++.h>
    using namespace std;
    const int M=1e3+3;
    
    struct node{
        int x,y;
        bool operator < (const node & b)const{
            if(x==b.x)
                return y<b.y;
            return x<b.x;
        }
        bool operator ==(const node & p)const {
            return x==p.x && y==p.y;
        }
    }a[M];
    map<node,int>mp;
    int main(){
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%d%d",&a[i].x,&a[i].y);
        }
        sort(a+1,a+1+n);
        n=unique(a+1,a+1+n)-(a+1);
        for(int i=1;i<=n;i++){
            for(int j=i;j<=n;j++){
                if(i==j){
                    mp[{a[i].x+a[j].x,a[i].y+a[j].y}]++;
                }
                else{
                    mp[{a[i].x+a[j].x,a[i].y+a[j].y}]+=2;
                }
            }
        }
        int ans=n;
        map<node,int>::iterator it;
        for(it=mp.begin();it!=mp.end();it++){
            ans=min(ans,n-(it->second));
        }
        printf("%d
    ",ans);
        return 0;
    }
    View Code

     E题:https://nanti.jisuanke.com/t/41387

    题意:给定一个序列,从每一个数后面比它大至少  的数中求出与它之间最大的距离。 如果没有则为 。

    题解:从后向前维护一个递增的队列,从后往前遍历,若当前的数大于队尾就进队,否 则从该队列中二分找最小的比自己大至少  的数,二者之间的距离即为答案。 若当前数小于队尾,那这个数一定没有队尾的数优,因为它既比队尾的数靠前,又比它 小。 

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int M=5e5+5;
    int a[M],que[M],id[M];
    int tot,ans[M];
    int main(){
        int n;
        ll m;
        scanf("%d%lld",&n,&m); 
        for(int i=1;i<=n;i++){
            scanf("%lld",&a[i]);
        }
    //    sort(a+1,a+1+n,cmp);
        que[++tot]=a[n],id[tot]=n;
        ans[n]=-1;
        for(int i=n-1;i>=1;i--){
            
            if(a[i]+m>que[tot]){
                ans[i]=-1;
            }
            else{
                int pos=lower_bound(que+1,que+1+tot,a[i]+m)-que;
                ans[i]=id[pos]-i-1;
            }
            if(que[tot]<a[i])
                que[++tot]=a[i],id[tot]=i;
        }
        for(int i=1;i<=n;i++){
            printf("%d",ans[i]);
            if(i!=n)
                printf(" ");
        }
            
        return 0;
    }
    View Code
  • 相关阅读:
    jython resources
    Installing a Library of Jython ScriptsPart of the WebSphere Application Server v7.x Administration Series Series
    jython好资料
    ulipad install on 64bit win7 has issue
    an oracle article in high level to descibe how to archtichre operator JAVA relevet project
    table的宽度,单元格内换行问题
    Linux常用命令大全
    dedecms系统后台登陆提示用户名密码不存在
    登录织梦后台提示用户名不存在的解决方法介绍
    Shell常用命令整理
  • 原文地址:https://www.cnblogs.com/starve/p/11483884.html
Copyright © 2011-2022 走看看