当前位置:网站首页>D 小红的构造题
D 小红的构造题
2022-06-13 04:37:00 【想吃蛋黄肉粽】
传送门:
D 小红的构造题
题意:构造一个长度不超过2e5的串,使得其中包含k个“red”子序列。(k<=1e14)
分析:一开始想先凑rreedd这样的串,然后再加字母。但是这样新加的字母具有后效性且子序列个数加不了1,做不了。
考虑rrrededed这样的串,再只再ed前加r,那么在任意位置加r都不会有后效性。如果r有x个,那么这样的串有x*(x+1)*x/2个子序列,显然x的长度在pow(1e14,1/3.0)级别,剩余k的长度也是x^2的级别。之后在每个ed前每加一个r,都会增加i(i+1)/2个子序列,且无后效性。好像,-最大的平方数也是属于数值快速递降的函数?反正跑得飞快。
代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
// cout<<pow(1e14,1/3.0)<<endl;
int k;
cin>>k;
int x=0;
while(1)
{
if(x*x*(x+1)/2>k)
{
x--;
break;
}
else x++;
}
cout<<x<<endl;
k-=x*x*(x+1)/2;
for(int i=1;i<=x;i++)
{
cout<<"r";
}
// int cnt=0;
for(int i=x;i>=1;i--)
{
while(k>=i*(i+1)/2)
{
k-=i*(i+1)/2;
cout<<"r";
// cnt++;
}
cout<<"ed";
}
cout<<endl;
// cout<<cnt<<endl;
}
边栏推荐
- Applet version update
- Blockly learning ----2 Code generation, grid, scaling, events, storage
- MySQL index
- Applet waterfall flow
- Notes on uni app
- EMC整改纲要
- php开发16退出模块
- Clear timer failure
- Powershell 加域 Add-Computer模块
- Notes on software test for programmers -- basic knowledge of software development, operation and maintenance
猜你喜欢
The data obtained from mongodb query data command is null
C#获取WebService接口的所有可调用方法[WebMethod]
Colab使用教程(超级详细版)及Colab Pro/Pro+评测
Crawler scrapy framework learning 1
EMC rectification outline
ACM ICPC
Redis data persistence
Explanation of line segment tree
[automated test] what you need to know about unittest
Ctfshow SQL injection (211-230)
随机推荐
Explanation of line segment tree
Webpack system learning (VIII) how contenthash can prevent browsers from using cache files
Set properties \ classes
Sword finger offer 56 - I. number of occurrences in the array
php开发博客系统的首页头部功能实现
PowerDesigner easy to use
2022氯化工艺操作证考试题库及模拟考试
Applet - uniapp realizes the functions of two-dimensional code picture pop-up and picture saving
PHP syntax
Develop go using vscode
Suffix Automaton
C#获取WebService接口的所有可调用方法[WebMethod]
PowerShell plus domain add computer module
Notes on software test for programmers -- basic knowledge of software development, operation and maintenance
2022 ICML | Pocket2Mol: Efficient Molecular Sampling Based on 3D Protein Pockets
H5 the blue background color appears when clicking the picture
Get verification code
Read paper 20 together: spatiotemporal prediction of PM2.5 concentration by idw-blstm under different time granularity
Solve the problem of running server nodemon reporting errors
Crawler scrapy framework learning 1