• 10.19-10.20 test


    2016 10.19-10.20 两天  题目by mzx

    Day1:

    T1:loverfinding

    题解:hash

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cstdlib>
     5 #include<string>
     6 #include<algorithm>
     7 #include<ctime>
     8 #include<cmath>
     9 #include<queue>
    10 using namespace std;
    11 #define FILE "loverfinding"
    12 #define pii pair<long long,long long>
    13 #define LL long long 
    14 #define up(i,j,n) for(int i=j;i<=n;i++)
    15 #define down(i,n,j) for(int i=n;i>=j;i--)
    16 #define max(x,y) ((x)>(y)?(x):(y))
    17 #define min(x,y) ((x)<(y)?(x):(y))
    18 #define abs(x) ((x)<0?(-(x)):(x))
    19 template<typename T>inline bool chkmax(T &a,T b){return a<b?a=b,true : false;}
    20 template<typename T>inline bool chkmin(T &a,T b){return a>b?a=b,true : false;}
    21 int read(){
    22     int x=0;char ch=getchar();bool flag=0;
    23     while(ch<'0'||ch>'9'){if(ch=='-')flag=1;ch=getchar();}
    24     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    25     return flag?-x:x;
    26 }
    27 namespace OI{
    28     void print(int x){printf("%d
    ",x);exit(0);}
    29     int n,x0,y0,xt,yt,cnt=1,nx,ny,dx,dy;
    30     int hx[10000000],hy[10000000],step=7,mod=9999777;
    31     bool vis[10000000];
    32     bool hash(int x,int y){
    33         int pos=abs((LL)(x+15214)*97%mod*(y+147)%mod*143%mod*71373)%mod;
    34         while(vis[pos]&&!(hx[pos]==x&&hy[pos]==y)){
    35             pos+=step;
    36             if(pos>mod)pos-=mod;
    37         }
    38         if(!vis[pos]){
    39             vis[pos]=1;hx[pos]=x;hy[pos]=y;return 1;
    40         }
    41         return 0;
    42     }
    43     void slove(){
    44         n=read(),nx=x0=read(),ny=y0=read(),xt=read(),yt=read();
    45         up(i,1,n){
    46             if(nx==xt&&ny==yt)print(cnt);
    47             if(hash(nx,ny))cnt++;
    48             dx=read(),dy=read();
    49             nx+=dx,ny+=dy;
    50         }
    51         printf("SingleDogMZX
    ");
    52     }
    53 }
    54 int main(){
    55     freopen(FILE".in","r",stdin);
    56     freopen(FILE".out","w",stdout);
    57     using namespace OI;
    58     slove();
    59     return 0;
    60 }
    View Code

    T2:snackstore

    题解:floyed

    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    #define FILE "snackstore"
    #define up(i,j,n) for(int i=j;i<=n;i++)
    template<typename T>inline bool chkmax(T &a,T b){return a<b?a=b,true : false;}
    template<typename T>inline bool chkmin(T &a,T b){return a>b?a=b,true : false;}
    namespace IO{
        char buf[1<<15],*fs,*ft;
        inline char gc(){return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;}
        inline int read(){
            int x=0,ch=gc();
            while(ch<'0'||ch>'9')ch=gc();
            while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-'0',ch=gc();
            return x;
        }
    }using namespace IO;
    namespace OI{
        const int maxn=110;
        const int inf=1000000001LL;
        int n,m,Q;
        struct node{
            int id,v;
            bool operator<(const node& b)const{return v<b.v;}
        }v[maxn];
        int A[maxn],pow[maxn];
        int f[maxn][maxn][maxn];
        void init(){
            n=read(),m=read(),Q=read();
            up(i,1,n)v[i].v=read(),v[i].id=i;
            int x,y,vv;
            for(int c=0;c<=n;c++)
                for(int i=1;i<=n;i++)
                    for(int j=1;j<=n;j++)
                        f[c][i][j]=inf;
            for(int i=1;i<=n;i++)f[0][i][i]=0;
            up(i,1,m){
                x=read(),y=read(),vv=read();
                if(vv<f[0][y][x])f[0][x][y]=f[0][y][x]=vv;
            }
            sort(v+1,v+n+1);
            for(int i=1;i<=n;i++)A[i]=v[i].id;
            for(int i=1;i<=n;i++)pow[i]=v[i].v;
            for(int c=1;c<=n;c++){
                memcpy(f[c],f[c-1],sizeof(f[c-1]));
                for(int i=1;i<=n;i++)
                    for(int j=1;j<=n;j++)
                        if(f[c][i][A[c]]+f[c][A[c]][j]<f[c][i][j])
                            f[c][i][j]=f[c][i][A[c]]+f[c][A[c]][j];
            }
            for(int c=0;c<=n;c++)
                for(int i=1;i<=n;i++)
                    sort(f[c][i]+1,f[c][i]+n+1);
        }
        int left,right,mid,ans;
        inline int find(int c){
            left=0,right=n;
            while(left<=right){
                mid=(left+right)>>1;
                if(c>=pow[mid])ans=mid,left=mid+1;
                else right=mid-1;
            }
            return ans;
        }
        inline int Find(int *a,int d){
            left=1,right=n;
            while(left<=right){
                mid=(left+right)>>1;
                if(a[mid]>d)right=mid-1;
                else left=mid+1,ans=mid;
            }
            return ans;
        }
        void slove(){
            init();
            int s,c,d,pos;
            up(i,1,Q){
                s=read(),c=read(),d=read();
                printf("%d
    ",Find(f[find(c)][s],d)-1);
            }
            return;
        }
    }
     
    int main(){
        freopen(FILE".in","r",stdin);
        freopen(FILE".out","w",stdout);
        using namespace OI;
        slove();
        return 0;
    }
    View Code

    T3:有点恶心,暂时搁置

    Day2:

    T1:three_squirrels

    题解:拓扑排序

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<string>
    #include<algorithm>
    #include<ctime>
    #include<cmath>
    #include<queue>
    using namespace std;
    #define FILE "three_squirrels"
    #define pii pair<long long,long long>
    #define LL long long 
    #define up(i,j,n) for(int i=j;i<=n;i++)
    #define down(i,n,j) for(int i=n;i>=j;i--)
    #define max(x,y) ((x)>(y)?(x):(y))
    #define min(x,y) ((x)<(y)?(x):(y))
    #define abs(x) ((x)<0?(-(x)):(x))
    template<typename T>inline bool chkmax(T &a,T b){return a<b?a=b,true : false;}
    template<typename T>inline bool chkmin(T &a,T b){return a>b?a=b,true : false;}
    int read(){
        int x=0;char ch=getchar();bool flag=0;
        while(ch<'0'||ch>'9'){if(ch=='-')flag=1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return flag?-x:x;
    }
    namespace OI{
        const int maxn=101000,mod=1000000007;
        int f[maxn];
        int n;
        struct node{
            int y,next;
        }e[2010000];
        int len=0,linkk[maxn];
        void insert(int x,int y){
            e[++len].y=y;
            e[len].next=linkk[x];
            linkk[x]=len;
        }
        int dfs(int x){
            if(f[x]!=-1)return f[x];
            f[x]=0;
            for(int i=linkk[x];i;i=e[i].next)f[x]=(f[x]+dfs(e[i].y))%mod;
            return f[x];
        }
        void slove(){
            memset(f,-1,sizeof(f));
            f[0]=1;
            n=read();int k,x;
            up(i,1,n){
                k=read();
                up(j,1,k){
                    x=read();
                    insert(i,x);
                }
            }
            printf("%d
    ",dfs(n));
        }
    }
     
    int main(){
        freopen(FILE".in","r",stdin);
        freopen(FILE".out","w",stdout);
        using namespace OI;
        slove();
        return 0;
    }
    View Code

    T2:savemzx

    题解:树形动规

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<string>
    #include<algorithm>
    #include<ctime>
    #include<cmath>
    #include<queue>
    using namespace std;
    #define FILE "savemzx"
    #define pii pair<long long,long long>
    #define LL long long 
    #define up(i,j,n) for(int i=j;i<=n;i++)
    #define down(i,n,j) for(int i=n;i>=j;i--)
    #define max(x,y) ((x)>(y)?(x):(y))
    #define min(x,y) ((x)<(y)?(x):(y))
    #define abs(x) ((x)<0?(-(x)):(x))
    template<typename T>inline bool chkmax(T &a,T b){return a<b?a=b,true : false;}
    template<typename T>inline bool chkmin(T &a,T b){return a>b?a=b,true : false;}
    int read(){
        int x=0;char ch=getchar();bool flag=0;
        while(ch<'0'||ch>'9'){if(ch=='-')flag=1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return flag?-x:x;
    }
    namespace OI{
        const int maxn=1010000;
        const LL inf=10000000000000000LL;
        char s[maxn];
        int next[maxn],n;
        bool vis[maxn];
        inline LL squ(int x){return (LL)x*x;}
        struct node{
            int y,next;
            LL v;
        }e[maxn<<1];
        int linkk[maxn],len=0;
        void insert(int x,int y,LL v){
            e[++len].y=y;
            e[len].next=linkk[x];
            linkk[x]=len;
            e[len].v=v;
        }
        LL w[maxn],maxx[maxn],maxx2[maxn],child[maxn];
        int fa[maxn];
        LL ans=0;
        void dfs(int x){
            for(int i=linkk[x];i;i=e[i].next){
                if(e[i].y==fa[x])continue;
                fa[e[i].y]=x;
                dfs(e[i].y);
                chkmax(ans,e[i].v);
                w[e[i].y]+=e[i].v;
                if(w[e[i].y]>maxx[x])maxx2[x]=maxx[x],maxx[x]=w[e[i].y];
                else if(w[e[i].y]>maxx2[x])maxx2[x]=w[e[i].y];
            }
            chkmax(ans,maxx[x]+maxx2[x]);
            w[x]=maxx[x];
        }
        void slove(){
            scanf("%s",s+1);n=strlen(s+1);
            int j=0;next[1]=0;
            insert(1,0,1);insert(0,1,1);
            for(int i=2;i<=n;i++){
                while(s[i]!=s[j+1]&&j)j=next[j];
                if(s[i]==s[j+1])j++;
                next[i]=j;
                insert(j,i,squ(j-i));
                insert(i,j,squ(i-j));
            }
            dfs(0);
            printf("%lld
    ",ans);
            return;
        }
    }
    int main(){
        freopen(FILE".in","r",stdin);
        freopen(FILE".out","w",stdout);
        using namespace OI;
        slove();
        return 0;
    }
    View Code

    T3:chocolatebox

    题解:请自行推导公式,数学题

    总的来说,这套题,两个T3(实现了让人不想看的目标),T2都是图论题,也需要一些分析和转化,总体不错;

    但这套题很恶心的地方是,卡常卡的太厉害(你能想象day1T1被卡的全T吗?),day1T2写完了正解后,交上去发现一直T,直到我抄了std的输入之后......

    桑心过度;

    祝初赛考出好成绩,啦啦啦......

  • 相关阅读:
    HYSBZ 1797 Mincut 最小割
    CodeForces 820B + 821C
    Codeforces 817+818(A~C)
    codeforces 816B Karen and Coffee (差分思想)
    840. Magic Squares In Grid ——weekly contest 86
    Linux 环境下 C++ 的开发编译
    838. Push Dominoes —— weekly contest 85
    836. Rectangle Overlap ——weekly contest 85
    六度空间
    835. Image Overlap —— weekly contest 84
  • 原文地址:https://www.cnblogs.com/chadinblog/p/5987370.html
Copyright © 2020-2023  润新知