zoukankan      html  css  js  c++  java
  • BestCoder Round #84

    A.贪心

    B.b题我昨晚看两个队友都没写出来,早上看觉得挺简单的,天真以为是要以ai结尾的连续的,wa1...然后知道是可以不连续的,做着做着忘了是要以ai结尾的,以为是前面的子序列最长就可以了,wa4...

    其实如果了解O(nlogn)的算法就可以很快想出来了,亏我还是写过模板的人,各种wa我也是醉了,每次只要在找到当前数字在LIS数组上的位置就可以了

    题目还是挺好的,我发现题目写的太少很容易看错题意呀,怎么破

    #include <iostream>
    #include <map>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    
    const int MAXN = 1e5+100;
    
    int a[MAXN],b[MAXN];
    int c[MAXN];
    
    int main()
    {
        int T;
        scanf("%d",&T);
        while(T--){
            int n;
            int top=0;
            int mmax = -1;
            scanf("%d",&n);
            for(int i=0;i<n;i++){
                scanf("%d",&a[i]);
                int l=0,r=top;
                while(l<r){
                    int m = l+(r-l)/2;
                    if(b[m]>=a[i]){
                        r = m;
                    }else{
                        l = m+1;
                    }
                }
                if(l==top){top++;b[l] = a[i];}
                else if(a[i]<b[l]){
                    b[l] = a[i];
                }
                //mmax = max(mmax,l+1);
                c[i] = l+1;
            }
            for(int i=0;i<n;i++){
                if(i==0)printf("1");
                else{
                    printf(" %d",c[i]);
                }
            }
            cout<<endl;
        }
    
        return 0;
    }
    View Code

     D.这道题目素数表的大小其实可以降的 我开了1e6,然后还有坑点没有想到,就是如果某个数是最大因数,那么它的的最小质因数比另个一个因子(当然也是最小因数)大,比如35(5*11),当他作为某个数的最大因子是,另一个因子必然是5以内的素数

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    typedef long long ll;
    const int MAXN = 1e6+1000;
    ll p[MAXN];
    int vis[MAXN];
    ll cnt;
    ll a[MAXN];
    
    void isprime(){
        cnt = 0;
        for(int i=2;i<MAXN;i++){
            if(!vis[i]){
                p[cnt++] = i;
                for(int j=i*2;j<MAXN;j+=i){
                    vis[j] = 1;
                }
            }
        }
    }
    
    
    int main()
    {
        isprime();
        //cout<<cnt<<endl;
        //for(ll i=0;i<10;i++)cout<<p[i]<<" ";
       // cout<<endl;
        int T;
        scanf("%d",&T);
        while(T--){
            ll n,d;
            scanf("%lld%lld",&n,&d);
            ll sum = 0;
            for(ll i=0;i<cnt&&p[i]*d<n;i++){
                sum++;
                if(d%p[i]==0){
                    break;
                }
            }
            cout<<sum<<endl;
        }
        //cout << "Hello world!" << endl;
        return 0;
    }
    View Code
    在一个谎言的国度,沉默就是英雄
  • 相关阅读:
    Android之Parcel
    Android常用的IPC通信
    Android之Surface绘制原理
    Android之Surface
    Android之SurfaceFlinger服务
    Android Service(服务)
    Android Service进阶之路
    Android之UI线程启动
    Android之Activity显示原理
    python17-Django进阶
  • 原文地址:https://www.cnblogs.com/EdsonLin/p/5700792.html
Copyright © 2011-2022 走看看