11.9考试爆炸记

不见晓岸杨柳翠,直冲云霄接浮云。
(1)回文数字
其实我们要求的是
9n+12i=1(2i1)10i1
然后就是喜闻乐见的差比数列求和
模数非质

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define mod 233333
#define inv 25926
using namespace std;
inline int read(){
    int i=0,f=1;
    char ch;
    for(ch=getchar();!isdigit(ch);ch=getchar())
        if(ch=='-') f=-1;
    for(;isdigit(ch);ch=getchar())
        i=(i<<3)+(i<<1)+(ch^48);
    return i*f;
}
int buf[1024];
inline void write(long long x){
    if(!x){putchar('0');return ;}
    if(x<0){putchar('-');x=-x;}
    while(x){buf[++buf[0]]=x%10,x/=10;}
    while(buf[0]) putchar(buf[buf[0]--]+48);
    return ;
}
int n,T;
inline int ksm(int a,int b){
    int ret=1;
    while(b){
        if(b&1) ret=(1ll*ret*a)%mod;
        a=(1ll*a*a)%mod;
        b>>=1;
    }
    return ret;
}
int solve(int x){
    x=(x+1)>>1;
    int a=(x*2-1)%mod,b=ksm(10,x),c=(b-10+mod)%mod;
    return ((1ll*a*b)%mod+mod-(2ll*c*inv)%mod-1)%mod;
}
signed main(){
    T=read();
    while(T--){
        n=read();
        write(solve(n));
        puts("");
    }
    return 0;
}

(2)路径统计
floyd 不解释

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
inline int read(){
    int i=0,f=1;
    char ch;
    for(ch=getchar();!isdigit(ch);ch=getchar())
        if(ch=='-') f=-1;
    for(;isdigit(ch);ch=getchar())
        i=(i<<3)+(i<<1)+(ch^48);
    return i*f;
}
int buf[1024];
inline void write(long long x){
    if(!x){putchar('0');return ;}
    if(x<0){putchar('-');x=-x;}
    while(x){buf[++buf[0]]=x%10,x/=10;}
    while(buf[0]) putchar(buf[buf[0]--]+48);
    return ;
}
#define stan 555
struct p{
    long long val;
    int id;
}poi[stan];
bool cmp(const p &a,const p &b){
    return a.valint f[stan][stan];
long long ans[stan][stan];
int n,m,to[stan],x,y,z;
signed main(){
    n=read();m=read();
    for(int i=1;i<=n;++i){
        poi[i].val=read();
        poi[i].id=i;
    }
    sort(poi+1,poi+n+1,cmp);
    for(int i=1;i<=n;++i)
        to[poi[i].id]=i;
    memset(f,127,sizeof(f));
    memset(ans,127,sizeof(ans));
    for(int i=1;i<=m;++i){
        x=read();y=read();z=read();
        f[to[x]][to[y]]=f[to[y]][to[x]]=z;
    }
    for(int i=1;i<=n;++i)
        f[i][i]=0;
    for(register int i=1;i<=n;++i)
        for(register int j=1;j<=n;++j)
            if(f[j][i]!=0x3f3f3f3f)
                for(register int k=1;k<=n;++k)
                    if(f[i][k]!=0x3f3f3f3f){
                        f[j][k]=min(f[j][k],max(f[j][i],f[i][k]));
                        if(f[j][k]!=0x3f3f3f3f&&j<=i&&k<=i)
                            ans[j][k]=min(ans[j][k],(long long)f[j][k]*max(poi[i].val,max(poi[j].val,poi[k].val)));
                    }
    for(register int i=1;i<=n;++i){
        for(register int j=1;j<=n;++j)
            write(ans[to[i]][to[j]]==0x3f3f3f3f?-1:ans[to[i]][to[j]]),putchar(' ');
        puts("");
    }
    return 0;
}

(3)字符串
其实是个后缀数组+RMQ
但暴力卡卡就过了

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
inline int read(){
    int i=0,f=1;
    char ch;
    for(ch=getchar();!isdigit(ch);ch=getchar())
        if(ch=='-') f=-1;
    for(;isdigit(ch);ch=getchar())
        i=(i<<3)+(i<<1)+(ch^48);
    return i*f;
}
int buf[1024];
inline void write(int x){
    if(!x){putchar('0');return ;}
    if(x<0){putchar('-');x=-x;}
    while(x){buf[++buf[0]]=x%10,x/=10;}
    while(buf[0]) putchar(buf[buf[0]--]+48);
    return ;
}
#define stan 222222
char s1[stan],s2[stan];
int n,m,k,tmp,ans;
signed main(){
    scanf("%s%s",s1+1,s2+1);
    k=read();
    n=strlen(s1+1);
    m=strlen(s2+1);
    if(nputs("0");
        return 0;
    }else{
        for(register int i=1;i<=n-m+1;++i){
            tmp=0;
            for(register int j=1;j<=m;++j){
                tmp+=(s1[i+j-1]!=s2[j]);
                if(tmp>k) break;
            }
            if(tmp<=k) ++ans;
        }
        write(ans);
        return 0;
    }
}

你可能感兴趣的:(OI,琐题集萃门,字符串算法纲,图论纲)