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. jeesite安装时Perhaps you are running on a JRE rather than a JDK

    使用自己本地安装的maven,启动jeesite报错: No compiler is provided in this environment. Perhaps you are running on ...

  2. mfc static控件 视频播放 闪屏问题 解决方案

    方案1: 我昨天刚在csdn上解决了这个问题,不是双缓冲和WS_CLIPCHILDREN还有背景擦出什么的问题,就是在你重画的时候要去掉这些控件(按钮什么的)区域, 闪屏是因为窗口大小发生改变时,由于 ...

  3. mysql LAST()函数 语法

    mysql LAST()函数 语法 作用:返回指定的字段中最后一个记录的值. 语法:SELECT LAST(column_name) FROM table_name 注释:可使用 ORDER BY 语 ...

  4. CodeForces 1100F Ivan and Burgers

    CodeForces题面 Time limit 3000 ms Memory limit 262144 kB Source Codeforces Round #532 (Div. 2) Tags da ...

  5. [BZOJ4305]数列的GCD:莫比乌斯反演+组合数学

    分析 一开始想的是对恰好\(k\)个位置容斥,结果发现对\(\gcd\)有些无从下手,想了想发现自己又sb了. 考虑对\(\gcd\)进行容斥处理,弱化条件,现在我们要求的是使\(\gcd\)是\(d ...

  6. C#中的事件委托

    C#中的事件与委托,对于我们写业务代码的程序员来说不常用,这就会导致经常忘记,这边再温习一下. //委托 public delegate void MyEventDelegateHandler(str ...

  7. [CSP-S模拟测试]:异或(数学)

    题目描述 给定$L,R$,我们希望你求出:$$\sum\limits_{i=L}^R\sum\limits_{j=L}^R(i\oplus j)$$其中这里的$\oplus$表示异或运算.答案对$10 ...

  8. Pyhton实用的format()格式化函数

    Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功能. 基本语法是通过 {} 和 : 来代替以前的 % . format 函数可以接受不限个参数 ...

  9. 一、基础篇--1.1Java基础-面向对象的特征

    面向对象的特征 封装.继承和多态 https://blog.csdn.net/jianyuerensheng/article/details/51602015 封装: 定义:封装就是将数据或函数等集合 ...

  10. webpack配置之webpack.config.js文件配置

    webpack配置之webpack.config.js文件配置 webpack.config.js webpack resolve  1.总是手动的输入webpack的输入输出文件路径,是一件非常繁琐 ...