zoukankan      html  css  js  c++  java
  • CodeChef November Challenge 2013 部分题解

    http://www.codechef.com/NOV13 还在比...我先放一部分题解吧...

    Uncle Johny 排序一遍

    struct node{
        int val;
        int pos;
    }a[MAXN];
    int cmp(node a,node b){
        return a.val < b.val;
    }
    int main(){
        int T,n,m;
        while(cin>>T){
            while(T--){
                cin>>n;
                for(int i = 0 ; i < n ; i++){
                    cin>>a[i].val;
                    a[i].pos = i+1;
                }
                cin>>m;
                sort(a,a+n,cmp);
                for(int i = 0 ; i < n ; i++){
                    if(a[i].pos == m){
                        cout<<i+1<<endl;
                        break;
                    }
                }
            }
        }
        return 0;
    }

    Missing some chairs 简单快速幂

    LL pow_mod(LL a, LL b){
        if(b == 1) return a;
        LL x = pow_mod(a,b/2),ret;
        if(b&1){
            ret = ((x * x)%MOD * a) % MOD;
        }else ret  = (x * x) % MOD;
        return ret;
    }
    int main(){
        int T;
        cin>>T;
        while(T--){
            LL n;
            cin>>n;
            LL c = pow_mod(2,n);
            cout<<c-1<<endl;
        }
        return 0;
    }

    Yet Another Cute Girl

    因子个数为素数的可能只有可能是pi^(pj-1)次幂..其中p是素数

    对于pj=2,区间素数筛,筛到sqrt(N)就行了...有O(n)的做法但我懒得写...其他的情况直接处理[L,R]内pi^(pj-1)的个数,加起来即可...

    考虑到pow可能爆LL,这个很坑..我应该是卡过的...

    LL cnt;
    bool prime[MAXN];
    LL pri[MAXN];
    bool p[MAXN];
    LL L,R;
    void pre_prime(){
        cnt = 0;
        prime[0] = prime[1] = 1;
        for(int i = 2 ; i < MAXN ; i++){
            if(!prime[i]) pri[cnt++] = i;
            for(int j = 0 ; j < cnt && i * pri[j] <= MAXN ; j++){
                prime[i * pri[j]] = 1;
                if(i % pri[j] == 0) break;
            }
        }
    }
    LL mpow(LL a, LL b){
        LL ret = 1;
        for(LL i = 0 ; i < b ; i++){
            LL tmp = ret * a;
            if(tmp > LINF || tmp < ret) return -1;
            ret = tmp;
        }
        return ret;
    }
    LL solve(){
        LL ct = 0;
        mem(p,0);
        for(LL i = 1 ; i < cnt ; i++){
            for(LL j = 0 ; j < cnt ; j++){
                LL q = mpow(pri[j],pri[i]-1);
                if(q == -1) break;
                if(q >= L && q <= R){
                    ct++;
                }
            }
        }
        for(LL j = 0 ; j < cnt ; j++){
            LL i;
            L % pri[j] == 0 ?  i = L : i = (L/pri[j]+1)*pri[j];
            if(i < MAXN && prime[i] == 0) i = i*2;
            for(i ; i <= R ; i+=pri[j]) p[i-L] = true;
        }
        for(LL i = L ; i <= R ; i++){
            if(p[i-L] == false && i != 1){
                ct++;
            }
        }
        return ct;
    }
    int main(){
        pre_prime();
        int T;
        cin>>T;
        while(T--){
            cin>>L>>R;
            LL res = solve();
            cout<<res<<endl;
        }
        return 0;
    }

    Square Digit Squares 预处理一遍完全平方数,就没多少个

    LL a[MAXN];
    int cnt = 0;
    bool judge(LL x){
        while(x){
            LL y = x%10;
            if(y != 1 && y != 0 && y != 4 && y != 9) return false;
            x/=10;
        }
        return true;
    }
    void pre(){
        for(LL i = 1 ; i*i <= (LL)pow((LL)10,(LL)10)+50 ; i++){
            if(judge(i*i)){
                a[cnt++] = i*i;
            }
        }
    }
    int main(){
        pre();
        int T;
        cin>>T;
        while(T--){
            LL ax,bx;
            cin>>ax>>bx;
            int ct = 0;
            for(int i = 0 ; i < cnt ; i++)
                if(a[i] >= ax && a[i] <= bx) ct++;
            cout<<ct<<endl;
        }
        return 0;
    }

    Superpowers of 2 还是幂取模,一套题出两次我就不吐槽了,也许LL会WA

    ULL change(ULL a){
        ULL ret = 0;
        int p[100],cnt = 0;
        while(a){
            p[cnt++] = a%2;
            a/=2;
        }
        for(int i = cnt-1 ; i >= 0 ; i--){
            ret = ret * 10 + p[i];
        }
        return ret;
    }
    ULL pow_mod(ULL a, ULL b){
        if(b == 1) return a;
        ULL x = pow_mod(a,b/2),ret;
        if(b&1) ret = ((x * x)%MOD * a) % MOD;
        else ret  = (x * x) % MOD;
        return ret;
    }
    int main(){
        int T;
        cin>>T;
        while(T--){
            int n;
            cin>>n;
            ULL x = pow_mod(2,change(n));
            cout<<(x*x)%MOD<<endl;
        }
        return 0;
    }
  • 相关阅读:
    总结c#和javascript中常见的相关的"空"
    javascript从未如此流行(JavaScript has never been so popular .)
    解决ajax调用中ie的缓存问题
    《.NET框架程序设计》第5章 基元类型、引用类型与值类型
    DataTable复制到新的DataTable并筛选
    《.NET框架程序设计》第1章 .NET开发平台体系架构 读后感
    《.NET框架程序设计》第4章 类型基础 读后感
    《.NET框架程序设计》第2章 第3章 读后感
    《道德经》程序员版第四十二章
    数据库设计总结
  • 原文地址:https://www.cnblogs.com/Felix-F/p/3414705.html
Copyright © 2011-2022 走看看