Codeforces - 1202D - Print a 1337-string... - 构造
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... - 构造的更多相关文章
- codeforces 709D D. Recover the String(构造)
题目链接: D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input s ...
- codeforces ~ 1009 B Minimum Ternary String(超级恶心的思维题
http://codeforces.com/problemset/problem/1009/B B. Minimum Ternary String time limit per test 1 seco ...
- iOS开发调试篇—Print Description of "string"
Print Description of "string":把 string 的信息输出到控制台.Copy:复制 string 的信息,包含变量名,类名和值.View Value ...
- 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 ...
- 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 ...
- [题解]Print a 1337-string...-数学(codeforces 1202D)
题目链接:https://codeforces.com/problemset/problem/1202/D 题意: 构造一串只由 ‘1’,‘3’,‘7’ 组成的字符串,使其 ‘1337’ 子序列数量为 ...
- codeforces 623A. Graph and String 构造
题目链接 给出一个图, 每个节点只有三种情况, a,b, c. a能和a, b连边, b能和a, b, c,连边, c能和b, c连边, 且无重边以及自环.给出初始的连边情况, 判断这个图是否满足条件 ...
- 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 ...
- Codeforces Gym 100425H H - Football Bets 构造
H - Football BetsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
随机推荐
- html acronym标签 语法
html acronym标签 语法 作用:定义首字母缩略词. 说明:如果首字母缩略词是一个单词,则可以被读出来,例如 NATO, NASA, ASAP, GUI.通过对只取首字母缩略词进行标记,您就能 ...
- 苹果CMSv10宝塔全自动定时采集教程
伙伴们在建立好自己的网站添加自定义资源库后,由于手动采集方式比较耗时间和精力更新也不够及时,是不是特别希望能有一个全自动定时采集方法来帮助网站增加视频资源解放自己的双手,那么现在就教大家如何用宝塔一步 ...
- Oracle rac11g 安装报INS41112
由于集群服务器上的数据库存储层要上双活,所以需要重置存储 不幸17服务器在重启后突然奔溃了,所以需要重新安装17服务器系统 在把18的软件全都卸载干净后,重新安装集群服务器,但却遇到了如下问题 多次针 ...
- android自定义camera以及uri和文件路径之间的转换
相对直接调用系统的camera,这种方法使用得相对还少一些.根据api文档,步骤如下: 定义一个预览类 可以参照<android高薪之路>这本书上面,有这种方法的一种完整实现 而对应的ac ...
- 修改docker下mysql配置
1.在/home/smile/docker/mysql/config/目录下增加一个文件 my.cnf # Copyright (c) , Oracle and/or its affiliates. ...
- SettingBar的点击事件拦截
接下来我们再来看另外一个案例,正如上面界面上显示的两个条目,车辆选择和始发地点选择,他们都有一个共同的特点就是都有共同的标题,内容和右剪头按钮,这种情况下我们都会把它封装成一个组合的自定义View来显 ...
- Ansible安装及常用模块
配置文件:/etc/ansible/ansible.cfg 主机列表:/etc/ansible/hosts 安装anslibe wget -O /etc/yum.repos.d/epel.repo ...
- linux系统PS命令,按CPU、内存使用率对进程排序
https://blog.csdn.net/weixin_42123737/article/details/90081318
- SSH port forwarding: bind: Cannot assign requested address
https://www.electricmonk.nl/log/2014/09/24/ssh-port-forwarding-bind-cannot-assign-requested-address/
- mysql查询时特殊字符转译
commons.lang String value = StringEscapeUtils.escapeSql(searchRequest.getSearchValue());