https://codeforces.com/contest/1202/problem/D

当时想的构造是中间两个3,然后前后的1和7组合出n,问题就是n假如是有一个比较大的质数因子或者它本身就是质数就会超长度。事实上程序会正确执行并分解成两个超大质数,不断putchar导致TLE。

正确的做法是通过3来主要组成答案,考虑133..337,中间有x个3,则有C(x,2)个组合,很明显可以发现在x=45000附近超过1e9的上限,而剩下的余数不会超过x=45000(或者在这个附近?)。

考虑怎么添加这个余数,可以在末尾用1来凑,或者在开头用7来凑。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll; ll C[460005];
int Ctop=460000; void initC(){
for(int i=1;i<=Ctop;++i)
C[i]=(1ll*i*(i-1))/2; /*for(int i=1;i<=100;++i)
cout<<C[i]<<endl;*/
return;
} int n; void solve(){
int num3=(upper_bound(C+1,C+1+Ctop,n)-C)-1;
//cout<<num3<<endl;
//cout<<C[num3]<<endl;
int num7=n-C[num3];
printf("133");
for(int i=1;i<=num7;++i)
printf("7");
for(int i=1;i<=num3-2;++i)
printf("3");
printf("7\n");
return;
} int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
#endif // Yinku
initC();
int T;
while(~scanf("%d", &T)) {
while(T--) {
scanf("%d",&n);
solve();
}
}
return 0;
}

Codeforces - 1202D - Print a 1337-string... - 构造的更多相关文章

  1. codeforces 709D D. Recover the String(构造)

    题目链接: D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input s ...

  2. codeforces ~ 1009 B Minimum Ternary String(超级恶心的思维题

    http://codeforces.com/problemset/problem/1009/B B. Minimum Ternary String time limit per test 1 seco ...

  3. iOS开发调试篇—Print Description of "string"

    Print Description of "string":把 string 的信息输出到控制台.Copy:复制 string 的信息,包含变量名,类名和值.View Value ...

  4. codeforces 628C C. Bear and String Distance

    C. Bear and String Distance time limit per test 1 second memory limit per test 256 megabytes input s ...

  5. codeforces 632C C. The Smallest String Concatenation(sort)

    C. The Smallest String Concatenation time limit per test 3 seconds memory limit per test 256 megabyt ...

  6. [题解]Print a 1337-string...-数学(codeforces 1202D)

    题目链接:https://codeforces.com/problemset/problem/1202/D 题意: 构造一串只由 ‘1’,‘3’,‘7’ 组成的字符串,使其 ‘1337’ 子序列数量为 ...

  7. codeforces 623A. Graph and String 构造

    题目链接 给出一个图, 每个节点只有三种情况, a,b, c. a能和a, b连边, b能和a, b, c,连边, c能和b, c连边, 且无重边以及自环.给出初始的连边情况, 判断这个图是否满足条件 ...

  8. AIM Tech Round 3 (Div. 1) B. Recover the String 构造

    B. Recover the String 题目连接: http://www.codeforces.com/contest/708/problem/B Description For each str ...

  9. Codeforces Gym 100425H H - Football Bets 构造

    H - Football BetsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

随机推荐

  1. mysql 特殊符号

    1.完全等于 <=> mysql> select null <=> null; +---------------+ | null <=> null | +-- ...

  2. golang rabbitmq实践 (二 实现简单的消息收发)

    1:驱动 本来打算自己写一个驱动的,后来发现github上面已经有了,那我就直接拿现成的了, 驱动采用 github.com/streadway/amqp ,直接import就可以啦! 2:excha ...

  3. [luogu]P1514 引水入城[搜索][记忆化][DP]

    [luogu]P1514 引水入城 引水入城 题目描述在一个遥远的国度,一侧是风景秀美的湖泊,另一侧则是漫无边际的沙漠.该国的行政区划十分特殊,刚好构成一个N 行M 列的矩形 ,如下图所示,其中每个格 ...

  4. Anaconda是如何进行版本管理的?

    创建不同的environments,在电脑中会有不同的文件夹 然后,当使用conda下载时,会下载到不同的env文件夹下(提前进行env切换) 那么不是在anaconda prompt命令行下下载的呢 ...

  5. HDU1254--推箱子(BFS+DFS)

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...

  6. onload,domcontentload区别+onload详解

    todo onLoad是的在页面所有文件加载完成后执行 DomContentLoad是Dom加载完成后执行,不必等待样式脚本和图片加载 domContentLoad更为合理, 原理: 如果是webki ...

  7. wannafly 练习赛10 f 序列查询(莫队,分块预处理,链表存已有次数)

    链接:https://www.nowcoder.net/acm/contest/58/F 时间限制:C/C++ 5秒,其他语言10秒 空间限制:C/C++ 262144K,其他语言524288K 64 ...

  8. 如何隐藏scroll-Y纵向滚动条,并不影响内容滚动的方法

    网上搜了很多关于隐藏滚动条的文章,发现很多都是只说了如何隐藏scroll-X横向滚动条,对scroll-Y纵向滚动条并没有明确的述说.本文章将介绍3种隐藏滚动条的方法,大家可以结合实际情况,参考文章内 ...

  9. Yii2.0简单隐藏index.php文件和模块配置和layout布局配置禁用和日志写入配置

    隐藏index.php文件 目的:想去掉浏览器地址栏中的 index.php?r= 这一块. 在/config/web.php中   ’components'=>[]   中添加如下代码: 'u ...

  10. serlvet操作数据库

    工具:eclipse 数据库工具:mysql java ee操作数据库,首先要导入数据库驱动文件,我用的是mysql 刚开始,很多人代码正确但是就是连接不上,原因就是忘了驱动文件的导入. 我的驱动文件 ...