[NOIP2017模拟]构造

2017.8.29 T2 1953

样例数据
输入

10

输出

0102010301

备注
【数据范围】
十个点 N 分别为:20 500 1023 1024 1400 1899 2200 5000 15000 25000 。
注意:代码长度不能超出 100 kb

分析:样例的构造法是二进制
显然这样的过不了的(只能到1023)
我们这样来构造这个序列
0110
0110 22222 0110
0110 22222 0110 33333333333333 0110 22222 0110
这样一直下去 (不断加同一个数直到这个数第一位的两倍,再把整个这个数之前的部分复制到后面来,继续加入新数)
观察可以发现这样构造没有造成浪费
可以通过 25000

代码

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<iomanip>
#include<queue>
#include<set>
using namespace std;

int getint()
{
    int sum=0,f=1;
    char ch;
    for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
    if(ch=='-')
    {
        f=-1;
        ch=getchar();
    }
    for(;ch>='0'&&ch<='9';ch=getchar())
        sum=(sum<<3)+(sum<<1)+ch-48;
    return sum*f;
}

string s;
int n,star,num;

int main()
{
    //freopen("number.in","r",stdin);
    //freopen("number.out","w",stdout);

    n=getint();
    s="0110";
    star=4;
    num=1;
    while(star<n)
    {
        num++;
        string s2;
        for(int i=star+1;i<=2*star+1;++i)
            s2+=num+'0';
        star=3*star+1;
        s=s+s2+s;
    }

    for(int i=0;i<n;++i)
        cout<<s[i];
    return 0;
}

本题结。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值