0
点赞
收藏
分享

微信扫一扫

CodeForeces 1202D Print a 1337-string(构造)


CodeForeces 1202D Print a 1337-string(构造)_#include

CodeForeces 1202D Print a 1337-string(构造)_i++_02

求能组成1337这个序列的串最短的串是什么

这道题我们很容易想到组合数,我可以有限考虑选择3,因为只有3是两个,这样可以使这个串尽可能的短。

但是选择3是不能满足我们组成任意个数的1337,这时候就通过1来解决,1只选择一个,所以可以组成任意个数。

先找到Cx2最接近N的x然后差几个就在最后337之前补足几个1,这样求得就是最小的。

AC代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdlib.h>
#include<queue>
#include<map>
#include<iomanip>
#include<math.h>
using namespace std;
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n;
scanf("%d",&n);
int a=0;
while((a+1)*a/2<=n)
{
a++;
}///C a 2;
///cout<<a<<endl;
printf("1");
for(int i=0;i<a-2;i++)
{
printf("3");
}
for(int i=0;i<n-a*(a-1)/2;i++)
{
printf("1");
}
printf("337\n");
}

return 0;
}

 

 

 

举报

相关推荐

0 条评论