`
java-mans
  • 浏览: 11412673 次
文章分类
社区版块
存档分类
最新评论

SGU 108 Self-numbers 2

 
阅读更多

sgu你敢不敢把内存搞大点!!!!!

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
using namespace std;

#ifdef _WIN32
#define i64 __int64
#define out64 "%I64d\n"
#define in64 "%I64d"
#else
#define i64 long long
#define out64 "%lld\n"
#define in64 "%lld"
#endif

#define FOR(i,a,b)      for( int i = (a) ; i <= (b) ; i ++)
#define FF(i,a)         for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a)        for( int i = (a)-1 ; i >= 0 ; i --)
#define S64(a)          scanf(in64,&a)
#define SS(a)           scanf("%d",&a)
#define LL(a)           ((a)<<1)
#define RR(a)           (((a)<<1)+1)
#define SZ(a)           ((int)a.size())
#define PP(n,m,a)       puts("---");FF(i,n){FF(j,m)cout << a[i][j] << ' ';puts("");}
#define pb              push_back
#define CL(Q)           while(!Q.empty())Q.pop()
#define MM(name,what)   memset(name,what,sizeof(name))
#define read            freopen("in.txt","r",stdin)
#define write           freopen("osr.txt","w",stdout)

const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-10;
const double pi = acos(-1.0);

struct zz
{
    int id;
    int s;
    bool operator < (const zz & cmp ) const
    {
        return s < cmp.s;
    }
}zx;

int n,k;
int temp;
int id;
int s[5555];
int a[5555];

vector<zz>v;

bool c1(int x)
{
    return !(x&1);
}

bool c2(int x)
{
     temp = x;
    if(x>=11)
    {
        x%=11;
        if(temp<110 && c1(x)) return true;
        x+=11;
        if(x<=18)
        {
            return c1(x);
        }
        return false;
    }
    else
    {
        return c1(x);
    }
}

bool c3(int x)
{
     temp = x;
    if(x>=101)
    {
        x%=101;
        if(temp < 1010 && c2(x)) return true;
        x+=101;
        if(x<=117)
        {
            return c2(x);
        }
        return false;
    }
    else
    {
        return c2(x);
    }
}

bool c4(int x)
{
     temp = x;
    if(x>=1001)
    {
        x%=1001;
        if(temp < 10010 && c3(x)) return true;
        x+=1001;
        if(x<=1026)
        {
            return c3(x);
        }
        return false;
    }
    else
    {
        return c3(x);
    }

}

bool c5(int x)
{
     temp = x;
    if(x>=10001)
    {
        x%=10001;
        if( temp<100010 && c4(x)) return true;
        x+=10001;
        if(x<=10035)
        {
            return c4(x);
        }
        return false;
    }
    else
    {
        return c4(x);
    }

}

bool c6(int x)
{
     temp = x;
    if( x>= 100001)
    {
        x%=100001;
        if(temp < 1000010 && c5(x)) return true;
        x += 100001;
        if(x<=100044)
        {
            return c5(x);
        }
        return false;
    }
    else
    {
        return c5(x);
    }
}

bool c7(int x)
{
     temp = x;
    if(x>=1000001)
    {
        x%=1000001;
        if(temp<10000010 && c6(x)) return true;
        x += 1000001;
        if(x<=1000053)
        {
            return c6(x);
        }
        return false;
    }
    else
    {
        return c6(x);
    }

}



int main()
{
    cin>>n;
    {
        int iv=0;
        v.clear();
        cin>>k;
        for(int i=1;i<=k;i++)
        {
            SS(s[i]);
            zx.s = s[i];
            zx.id = i;
            v.pb(zx);
        }
        sort(v.begin(),v.end());
        zx.s=-1;
        zx.id=0;
        v.push_back(zx);
        id = 0;
        for(int i=1;i<=n;i++)
        {
            if(!c7(i))
            {
                id++;
                if(id == v[iv].s)
                {
                    a[v[iv].id] = i;
                    iv++;
                    while(id == v[iv].s)
                    {
                        a[v[iv].id] = i;
                        iv++;
                    }
                    if(iv == k+1)
                    {
                        break;
                    }
                }
            }
        }
        cout<<id<<endl;

        FOR(i,1,k-1)
        {
            printf("%d ",a[i]);
        }
        printf("%d\n",a[k]);
    }
 //   system("pause");
    return 0;


}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics