zoukankan      html  css  js  c++  java
  • 贝贝的波浪数

    #include<iostream>
    #include<string>
    #include<stdio.h>
    #include<algorithm>
    using namespace std;
    bool mark[10000005]; 
    int a,b,L,R,K;
    int A[1005];
    bool check(int res){
        int k=0;
        for(int i=a;i<=b;i++){
            int x=res,t=0;
            while(x){
                A[t++]=x%i;
                x/=i;
            }
            if(t==1)continue;
            if(A[0]==A[1])continue;
            bool f=true;
            for(int j=2;j<t;j++){
                if(A[j]!=A[j-2])f=false;
            }
            if(f)k++;
        }
        return k==K;
    }
    void solve(int x,int y,int B){
        int t=0;
        long long res=0;
        while(1){
            if(t%2==0)res=res*B+x;
            else res=res*B+y;
            t++;
            if(res>R)break;
            if(res>=L&&check(res))mark[res]=1;
        }
    }
    int main(){
        int k,ans=0;
        scanf("%d %d %d %d %d",&a,&b,&L,&R,&K);
        for(int i=a;i<=b;i++){
            for(int i1=1;i1<i;i1++){
                for(int i2=0;i2<i;i2++){
                    solve(i1,i2,i);
                }
            }
        }
        int res=0;
        for(int i=L;i<=R;i++)
            if(mark[i])
                printf("%d
    ",i);
        //printf("%d
    ",i);
        return 0;
    }
  • 相关阅读:
    Aizu
    Aizu
    POJ
    POJ
    POJ
    UVA
    manacher
    Gym
    Gym
    Gym
  • 原文地址:https://www.cnblogs.com/shiningrise/p/6645679.html
Copyright © 2011-2022 走看看