20162017-ct-s03e02-codeforces-trainings-season-3-episode-2-en-I Painting the natural numbers

题意:用10种颜色染1-n这n个数字,染色需满足:a,b(a可以等于b)同一种颜色,则a+b必须是另一种颜色(n<=25000)

题解:若当前已用k种颜色染好n个数字,则可以扩展成3n+1个数字:

{n个数字,k种颜色}{n+1个,第(k+1)种颜色}{n个数字,k种颜色}


用这种方法10种颜色可以达到29000


#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

const int N=30000;
int n;
int a[N];
int main()
{
    int Now=1;a[1]=0;
    for (int K=1;K<10;K++){
        for (int i=Now+1;i<=Now+Now+1;i++)a[i]=K;
        for (int i=2*Now+2;i<=Now*3+1;i++)a[i]=a[i-Now*2-1];
        Now=3*Now+1;
    }
    cin>>n;
    for (int i=1;i<=n;i++)printf("%d",a[i]);
    return 0;
}


你可能感兴趣的:(20162017-ct-s03e02-codeforces-trainings-season-3-episode-2-en-I Painting the natural numbers)