zoukankan      html  css  js  c++  java
  • bzoj2793: [Poi2012]Vouchers

      傻逼题...

      直接记录x倍数已经扫到哪里了,每次接着上次的扫就好,因为幸运数范围只有100w,扫到100w就停,根据调和级数复杂度为O(NlogN)。

      记得开long long!!!T T

    #include<iostream> 
    #include<cstring>
    #include<cstdlib>
    #include<cstdio>
    #include<cmath> 
    #include<algorithm> 
    #define ll long long
    using namespace std;
    const int maxn=1000010, inf=1e9;
    int n, m, x, cnt;
    int now[maxn];
    ll num, ans[maxn];
    bool lucky[maxn], used[maxn];
    inline void read(int &k)
    {
        int f=1; k=0; char c=getchar();
        while(c<'0' || c>'9') c=='-'&&(f=-1), c=getchar();
        while(c<='9' && c>='0') k=k*10+c-'0', c=getchar();
        k*=f;
    }
    int main()
    {
        read(n);
        for(int i=1;i<=n;i++) read(x), lucky[x]=1; 
        for(int i=1;i<=1000000;i++) now[i]=i;
        read(m); num=0;
        for(int i=1;i<=m;i++)
        {
            read(x);
            for(int j=1;j<=x;j++)
            {
                for(int k=now[x];k<=1000000;k+=x, now[x]=k)
                    if(!used[k]) break;
                if(now[x]>1000000)break;
                used[now[x]]=1;
                if(lucky[now[x]]) ans[++cnt]=num+j;
            }
            num+=x;
        }    
        printf("%d
    ", cnt);
        for(int i=1;i<=cnt;i++) printf("%lld
    ", ans[i]); 
    }
    View Code
  • 相关阅读:
    stl(8)常见的算法
    stl(7)几种常见的迭代器
    stl(6)deque容器
    pre_exam_exercise1
    全为1时计算个数,出现0返回0
    COMP9021--7.18
    lecture 5 Basics of Map Algebra
    COMP9021--7.15
    Lecture 4补充
    COMP9021--7.4
  • 原文地址:https://www.cnblogs.com/Sakits/p/7744027.html
Copyright © 2011-2022 走看看