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/ ...
随机推荐
- BZOJ 2121: 字符串游戏 区间DP + 思维
Description BX正在进行一个字符串游戏,他手上有一个字符串L,以及其他一些字符串的集合S,然后他可以进行以下操作:对 于一个在集合S中的字符串p,如果p在L中出现,BX就可以选择是否将其删 ...
- C/C++中结构体引用中箭头->与点.的区别
1.作用 ->主要用于类类型的指针访问类的成员,而.运算符,主要用于类类型的对象访问类的成员. 举例: class A { public : int member; } A a; //定义一个结 ...
- 大哥带的Orchel数据库的盲注入bool型
0X01判断闭合 ?username=SMITH' 错误 ?username=SMITH'' 正确 ?username=SMITH' and ascii(substr((select user fro ...
- bootstrap的editTable实现方法
首先下载基于bootstrap的源码到本地.引用相关文件. <link href="/Content/bootstrap/css/bootstrap.min.css" rel ...
- 浅谈javaweb三大框架和MVC设计模式
一.MVC设计模式 1.MVC的概念 首先我们需要知道MVC模式并不是javaweb项目中独有的,MVC是一种软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model).视图(Vie ...
- WINDOWS API 大全(一)
1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WNetAddConnection2 创建同一个网络资源的连接 WNetAddConnection3 创建同 ...
- 异步 map 和模块打包
概述 本文是我在查资料的时候学到的一些东西,记录下来,供以后开发时参考,相信对其他人也有用. 参考资料: 异步函数 - 提高 Promise 的易用性 深入 CommonJs 与 ES6 Module ...
- WPF中的WndProc
其实,在WPF中,要想利用WndProc来处理所有的事件,需要利用到SourceInitialized Event,首先需要创建一个HwndSource对象,然后利用其AddHook方法来将所有的w ...
- 看看 Delphi XE2 为 VCL 提供的 14 种样式
看看 Delphi XE2 为 VCL 提供的 14 种样式 其实只提供了 13 个 vsf 样式文件, 还有默认的 Windows 样式, 共 14 种. 在空白窗体上添加 ListBox1 等控件 ...
- CSS3——注释 id 和 class 选择器 css创建(外部、内部、内联样式表)
注释 /* 注释内容 */ id 和 class 选择器 id ID属性不要以数字开头,数字开头的ID在 Mozilla/Firefox 浏览器中不起作用 < ...