找个例题:
http://codeforces.com/contest/1328/problem/B

B. K-th Beautiful String
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
For the given integer n (n>2) let’s write down all the strings of length n which contain n−2 letters ‘a’ and two letters ‘b’ in lexicographical (alphabetical) order.

Recall that the string s of length n is lexicographically less than string t of length n, if there exists such i (1≤i≤n), that si<ti, and for any j (1≤j<i) sj=tj. The lexicographic comparison of strings is implemented by the operator < in modern programming languages.

For example, if n=5 the strings are (the order does matter):

aaabb
aabab
aabba
abaab
ababa
abbaa
baaab
baaba
babaa
bbaaa
It is easy to show that such a list of strings will contain exactly n⋅(n−1)2 strings.

You are given n (n>2) and k (1≤k≤n⋅(n−1)2). Print the k-th string from the list.

Input
The input contains one or more test cases.

The first line contains one integer t (1≤t≤104) — the number of test cases in the test. Then t test cases follow.

Each test case is written on the the separate line containing two integers n and k (3≤n≤105,1≤k≤min(2⋅109,n⋅(n−1)2).

The sum of values n over all test cases in the test doesn’t exceed 105.

Output
For each test case print the k-th string from the list of all described above strings of length n. Strings in the list are sorted lexicographically (alphabetically).

Example
inputCopy
7
5 1
5 2
5 8
5 10
3 1
3 2
20 100
outputCopy
aaabb
aabab
baaba
bbaaa
abb
bab
aaaaabaaaaabaaaaaaaa

题目大意:
input: t,n,k
t 组数据, 字符串长度 n , 输出第k 个字符串字符串从尾部bb开始排列,主要是确定b的位置,设 pre, lat指向b,
i , j 分别为 pre,lat 的左移单位数初始 pre = n  - 2 ,lat = n -1
题目转换为,寻找 i ,j 与 k 的关系

然后列个表看看:
i 0 1 1 2 2 2 3 3 3 3
j 0 0 1 0 1 2 0 1 2 3
s 1 2 3 4 (这一行表示每一个i 对应 排列种数)
k 1 2 3 4 5 6 7 8 9 10

i 与 s : s = i + 1
s 与 k: s(s+1)/2 (确定每一个边界对应)
j 与 k: k(n-1) + j + 1 = k;

通过第二个条件确定边界就基本解决了;
如下:

#include <iostream>
using namespace std;
typedef long long ll;void get_pre(int& pre,int& lat,const int n,const ll k)
{int i = 0, j = 0;for(int u = 0;u<n;++u){int s = u + 1;if((ll)s * (s + 1)/ 2 >= k){i = u ;break;}}//ll before= (ll)i * (i + 1) / 2;j = k - before - 1;//pre -= i;lat -= j;
}
//
int main()
{ios::sync_with_stdio(false), cin.tie(0);int t, n;ll k;while (cin >> t){while (t--){cin >> n >> k;int pre = n - 2, lat = n - 1;get_pre(pre, lat, n, k);for (int i = 0; i < n; ++i){if (i == pre || i == lat)cout << 'b';·elsecout << 'a';}cout << '\n';}}return 0;
}

好像也类似 112123.。。。


1121231234----1 2 3 4 5 6 7 8 9 10类: 寻找第k个数

1
1 2
1 2 3
....
1 2 3 4 5... n

第n行有 n个数,
1 2 3 4 5…等差数列 Sn = n(n+1)/2
通过遍历找到所在行
if(Sn>k) break; //此时得到大一个的n
所在行 即:n -1
则所在列:k - S(n-2)
所在列即为该数字。

112123---123456相关推荐

  1. php 挂马 密码123456,admin密码-常用密码加密md5值,123456,admin,admin888

    一 : 常用密码加密md5值,123456,admin,admin888 123456这个经md5算法加密之后是多少? 16位:49ba59abbe56e057 32位:e10adc3949ba59a ...

  2. 不可思议!乌克兰国防军队的系统账密居然是 admin 和 123456...

    编辑:可可.整理 开发者技术前线 2020年被用烂大街的密码,500 多万个泄漏密码表明,共有近 3% 的人使用"123456"作为密码.而最近知名黑客网站 Have I Been ...

  3. java---某人在玩游戏的时候输入密码123456后成功进入游戏(输错5次则被强行退出),要求用程序实现密码验证的过程。

    题目: 某人在玩游戏的时候输入密码123456后成功进入游戏(输错5次则被强行退出),要求用程序实现密码验证的过程,要求如下: (1) 使用System.in包装为字符流读取键盘输入. (2) Buf ...

  4. mysql 123456_$myconn=mysql_connect(192.168.1.xxx,root,123456);怎么连不上数据库啊?

    你的位置: 问答吧 -> PHP -> 问题详情 $myconn=mysql_connect("192.168.1.xxx","root",&quo ...

  5. 2020了,最流行的密码依旧是123456

    喜欢就关注我们吧! 密码管理器 NordPass 于日前发布的一份报告中揭示了 2020 年最常见的密码,并提供了有关如何使密码更安全的建议. 根据 NordPass 的研究,在今年 200 种最常用 ...

  6. mysql远程连接权限grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘123456‘ with grant option语句报错

    mysql远程连接权限grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option语句报错 记录 ...

  7. Javascript报错Failed to execute ‘querySelectorAll‘ on ‘Document‘: ‘#123456‘ is not a valid sele

    Javascript报错:Failed to execute 'querySelectorAll' on 'Document': '#123456' is not a valid selector 解 ...

  8. mysql 123456_MySQL字符串中抽取数值的方法 select -(-'123456@163.com'); 很牛逼

    MySQL的字符串函数非常多,以至于有时候我不知道该如何灵活的使用这些函数. 字符串基本信息函数     collation  convert,char_length等 加密函数   password ...

  9. 正则表达式 判断 连号如“123456”、同号如“888888”、连同号如“112233”“222333”...

    正则表达式 判断 连号如"123456".同号如"888888".连同号如"112233""222333" import ...

  10. net user test 123456 /add

    net  user test 123456 /add 转载于:https://www.cnblogs.com/seasonsstory/p/3432887.html

最新文章

  1. Tensorflow函数——tf.variable_scope()
  2. 面向对象课程第二单元作业总结
  3. BottomNavigationView+ViewPager+Fragment仿微信底部导航栏
  4. Windows 2000/XP/2003超级工具
  5. 你不得不知道的Visual Studio 2012(3)- 创建Windows应用程序
  6. linux系统判断是否重启、关机、查询登录诊断分析简介
  7. 如何在Ubuntu里安装Helm
  8. 【Manacher】绿绿和串串(luogu 5446)
  9. windows系统安装下GCC编译器
  10. Velodyne 16线三维激光雷达
  11. 第2章——R的数据组织
  12. Boost库编译指南
  13. 自学前端到上岸工作系列之css03
  14. 微信公众号头像如何修改
  15. 神通广大的WiFi劫持工具:Mana
  16. linux安装mysql8.11_Ubuntu安装MySQL任意版本(18.04亲测)
  17. python获取gps数据_Python GPS模块:读取最新的GPS数据
  18. rsa前后端加密流程_HTTPS 温故知新(三)——直观感受 TLS 握手流程(中)
  19. sdcms php版手册,目录结构及说明
  20. 两个mysql数据同步

热门文章

  1. 一篇好文,以在迷茫时品味…………
  2. 如何生成火焰图以及火焰图基本介绍
  3. 今天没有带U盘,把代码拷到网上再回家贴
  4. Ubuntu系统如何用网线连上路由器上网
  5. oracle 12C ADG Far Sync 配置实验
  6. 【NOIP2017提高组】轰炸
  7. 关于网络传输中速度达不到很高的原因
  8. 应用程序无法正常启动0x000007b,请单击“确定”关闭应用程序(不要着急,先定位问题)
  9. 规范化、归一化、标准化、中心化、正则化
  10. PAP和CHAP认证方式