首页 > 其他 > 详细

D - Print a 1337-string... CodeForces - 1202D

时间:2019-10-19 11:18:32      阅读:59      评论:0      收藏:0      [点我收藏+]
#include <bits/stdc++.h>
using namespace std;
/*
给你一个数n,让你求一个串,里面的子序列“1337”的数量恰好为n
开始时用1的数量*C(m,2)*7的数量,不好处理
题解中用13377773333337的形式,使得C(m,2)+7的数量=n;
这样更好处理
*/
typedef long long ll;
const int maxn=1e9;
int a[100000];//记录C(i,2)
int cnt;//纪律数组的长度
void init()
{
    for(int i=2; i<100000; i++)
    {
        if(i*(i-1)/2>maxn)
            {cnt=i;
             break;
            }
        a[i]=i*(i-1)/2;
    }
}
int main()
{
//    ll m=(ll)((ll)1<<31)-1;//必须把1弄成ll
    int t,n;
    scanf("%d",&t);
    init();
    while(t--)
    {
        scanf("%d",&n);
        int pos=upper_bound(a,a+cnt,n)-a-1;
        int y=n-a[pos];//7的个数
        printf("133");
        for(int i=0; i<y; i++)
            printf("7");
        for(int i=0; i<pos-2; i++)
            printf("3");
        printf("7\n");
    }
    return 0;
}

 

D - Print a 1337-string... CodeForces - 1202D

原文:https://www.cnblogs.com/zhangzhenjun/p/11702888.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!