1. 程式人生 > >10.5 simulated match

10.5 simulated match

esp set int ems oid ++i edge code size

技術分享

技術分享

well,the code is the best language

#include<cstdio>
using namespace std;
#define ct   register int
#define fr(a,b,c)   for(ct a=b;a<=c;a++)
#define init(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout); 
int read(){ct f=1,x=0;char c=getchar();
   for(;c<0||c>9;c=getchar())if
(c==-)f=-1; for(;0<=c&&c<=9;c=getchar())x=(x<<1)+(x<<3)+(c^48);return x*f;} char st[100005];int n,p; void Build(int x){ fr(i,x,n)fr(j,0,p-1) if((i<=1||j!=st[i-1]-a)&&(i<=2||j!=st[i-2]-a)){st[i]=j+a;break;} printf("%s",st+1); }
int main(){init("string");n=read();p=read();scanf("%s",st+1); for(ct i=n;i;--i)fr(j,st[i]-a+1,p-1) if((i<=1||j!=st[i-1]-a)&&(i<=2||j!=st[i-2]-a)){st[i]=j+a;Build(i+1);return 0;} puts("NO");return 0; }


技術分享

技術分享

well,the code is the best language

#include<cstring>
#include<cstdio>
using namespace std;
#define ct   register int
#define fr(a,b,c)   for(ct a=b;a<=c;a++)
#define init(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout); 
int read(){ct f=1,x=0;char c=getchar();
   for(;c<0||c>9;c=getchar())if(c==-)f=-1;
   for(;0<=c&&c<=9;c=getchar())x=(x<<1)+(x<<3)+(c^48);return x*f;}
int n,ans=0,f[100005];
int main(){init("sorting");n=read();int x,mx;
    fr(i,1,n)x=read(),mx=f[x-1],ans=ans>mx+1?ans:mx+1,f[x]=mx+1;
    printf("%d",n-ans);return 0;
}


技術分享

技術分享

技術分享

well ,the code is the best language

#include<algorithm>
#include<cstring>
#include<cstdio>
#define MN 2000
using namespace std;
#define ct   register int
#define fr(a,b,c)   for(ct a=b;a<=c;a++)
#define init(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout); 
int read(){ct f=1,x=0;char c=getchar();
   for(;c<0||c>9;c=getchar())if(c==-)f=-1;
   for(;0<=c&&c<=9;c=getchar())x=(x<<1)+(x<<3)+(c^48);return x*f;}
int head[MN+5],cnt=0,n,m,d[MN+5][MN+5],q[MN+5],top,ans,a[4];
int mx[3][MN+5],from[3][MN+5],Mx[3][MN+5],From[3][MN+5];
struct edge{int to,next;}e[MN*2+5];
inline void ins(int f,int t){e[++cnt]=(edge){t,head[f]};head[f]=cnt;}
void Add2(int x,int y,int len){
    if(len>Mx[0][x])From[2][x]=From[1][x],Mx[2][x]=Mx[1][x],
        From[1][x]=From[0][x],Mx[1][x]=Mx[0][x],From[0][x]=y,Mx[0][x]=len;
    else if(len>Mx[1][x])
        From[2][x]=From[1][x],Mx[2][x]=Mx[1][x],From[1][x]=y,Mx[1][x]=len;
    else if(len>Mx[2][x])From[2][x]=y,Mx[2][x]=len;
}
void Add1(int x,int y,int len){
    if(len>mx[0][x])from[2][x]=from[1][x],mx[2][x]=mx[1][x],
        from[1][x]=from[0][x],mx[1][x]=mx[0][x],from[0][x]=y,mx[0][x]=len;
    else if(len>mx[1][x])
        from[2][x]=from[1][x],mx[2][x]=mx[1][x],from[1][x]=y,mx[1][x]=len;
    else if(len>mx[2][x])from[2][x]=y,mx[2][x]=len;
}
inline void R(int A,int B,int C,int D,int res){if(res>ans) ans=res,a[0]=A,a[1]=B,a[2]=C,a[3]=D;}
int main(){init("travel");n=read();m=read();memset(d,63,sizeof(d));
    for(ct i=1,j;i<=m;++i)j=read(),ins(j,read());
    fr(i,1,n){d[i][q[top=1]=i]=0;
        fr(j,1,top)
            for(ct k=head[q[j]];k;k=e[k].next)
                if(d[i][q[j]]+1<d[i][e[k].to])d[i][q[++top]=e[k].to]=d[i][q[j]]+1;}
    fr(i,1,n)fr(j,1,n)if(i!=j&&d[i][j]<1e9)Add2(j,i,d[i][j]),Add1(i,j,d[i][j]);
    fr(i,1,n)fr(j,1,n)if(i!=j&&d[i][j]<1e9)
            fr(k,0,2)if(From[k][i]!=j&&From[k][i])
                fr(l,0,2)if(from[l][j]!=i&&from[l][j]!=From[k][i]&&from[l][j])
                    R(From[k][i],i,j,from[l][j],Mx[k][i]+d[i][j]+mx[l][j]);
    printf("%d %d %d %d",a[0],a[1],a[2],a[3]);return 0;
}

10.5 simulated match