当前位置:网站首页>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;
}边栏推荐
- Redis
- Knife4j aggregation 2.0.9 supports automatic refresh of routing documents
- Google Chrome browser reports an error: net:: err_ BLOCKED_ BY_ CLIENT
- [sword finger offer] interview question 25 Merge two ordered linked lists
- Ionic Cordova command line
- php开发16退出模块
- Set properties \ classes
- 一致性哈希的简单认识
- 第三方评论插件
- Redis
猜你喜欢

第007天:go语言字符串

Li Kou brush question 647 Palindrome substring

前几年的互联网人vs现在的互联网人

Tree array explanation

【Try to Hack】upload-labs通关(暂时写到12关)

Express framework knowledge - Art template template, cookie, session

Li Kou brush question 338 Bit count

120. 三角形最小路径和-动态规划

How to implement a custom jdbc driver in only four steps?

VGA display based on de2-115 platform
随机推荐
120. 三角形最小路径和-动态规划
Lenovo notebook computer uses the insert key. When the mouse becomes a small square, how to solve it
Powershell 加域 Add-Computer模块
前几年的互联网人vs现在的互联网人
php开发博客系统的首页头部功能实现
The could not find com scwang. smart:refresh-layout-kernel:2.0.3. Required by: project: the app cannot load the third-party package
This Sedata uses multiple methods to dynamically modify objects and values in arrays. Object calculation properties
PHP development 14 compilation of friendship link module
2022 oxidation process operation certificate examination question bank and simulation examination
Colab使用教程(超级详细版)及Colab Pro/Pro+评测
Common ways to traverse map sets
Day 007: go language string
Serial communication learning
Recommended temporary online image compression tool
How to implement a custom jdbc driver in only four steps?
Solve the problem of running server nodemon reporting errors
Tita performance treasure: remote one-on-one discussion
剑指 Offer 11. 旋转数组的最小数字-二分查找
C盘无损移动文件
Read paper 20 together: spatiotemporal prediction of PM2.5 concentration by idw-blstm under different time granularity