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/ ...
随机推荐
- vue中为computed计算属性传参遇到的问题,已解决
首先介绍下项目背景, 需要将 dataList 中的 item.stars 属性传入 computed 返回要展示的值 部分代码如下(请不要纠结为什么这么做,数据格式确认如此): <li cla ...
- vue学习-day02(自定义指令,生命周期)
目录: 1.案例:品牌管理 2.Vue-devtools的两种安装方式 3.过滤器,自定义全局或私有过滤器 4.鼠标按键事件的修饰符 5.自定义全局指令:让文本框获取焦点 ...
- html a标签 语法
html a标签 语法 作用:<a> 标签定义超链接,用于从一张页面链接到另一张页面. 直线电机滑台 说明:<a> 元素最重要的属性是 href 属性,它指示链接的目标.在所有 ...
- JAVA批量文件下载
1,看看我们封装的方法 方法中有三个参数:视频url,文件夹路径,视频名称. 调用方法进行下载. 2,看看结果 打印结果 文件夹下的视频下载成功 详细的参数配置可以参考我写的这篇文章:http://b ...
- React 项目 ant design 的 CheckboxGroup 验证
使用 ant design 提供的 getFieldDecorator 进行验证 一般开始使用默认选中 <FormItem> {getFieldDecorator('checkProtoc ...
- 十、Springboot之thymeleaf与jsp共存
: pom.xml添加依赖 <!--thymeleaf整合JSP需要用到下面的依赖--> <dependency> <groupId>org.thymeleaf&l ...
- Spring 缓存注解解析过程
Spring 缓存注解解析过程 通过 SpringCacheAnnotationParser 的 parseCacheAnnotations 方法解析指定方法或类上的缓存注解, @Cacheable ...
- ubuntu用mentohust连接ruijie
32位 http://download.csdn.net/detail/yan456jie/8720395 64位 http://download.csdn.net/detail/yan456jie ...
- MYSQL5.7源码包编译安装
Centos下用cmake编译安装MySQL 5.7安装依赖包yum -y install gcc gcc-c++ ncurses ncurses-devel cmake下载相应源码包cd /usr/ ...
- current_url 获取当前测试地址和page_souce获取当前网页源代码
from selenium import webdriverdriver = webdriver.Firefox()driver.get("https://www.baidu.com&quo ...