*[hackerrank]Lexicographic paths
https://www.hackerrank.com/contests/w9/challenges/lexicographic-steps
这题还是折腾很久的。题目意思相当于,比如有两个1两个0,那么找组成的数里第k大的。想法就是,如上例,假如K为4,那么先看后两位够了么C(2,2)=1,不够,那么看后三位C(3,2)=3,也不够,后四位是C(4,2)=6,够了,那么第一个1在倒数第4位。然后减去C(3,2)继续做。
#include <iostream>
#include <vector>
using namespace std; int main() {
int t;
cin >> t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
k++;
string s;
s.resize(m + n);
while (m > 0) {
// find pos for the first remaining V
int x = m;
int lastR = 0;
int r = 1;
while (k > r) {
lastR = r;
x++;
r = r * x / (x - m);
}
// r >= k, fill one V
s[s.size() - x] = 'V';
m--;
k -= lastR;
}
for (int i = 0; i < s.size(); i++) {
if (s[i] != 'V')
s[i] = 'H';
}
cout << s << endl;
}
}
*[hackerrank]Lexicographic paths的更多相关文章
- soj 1015 Jill's Tour Paths 解题报告
题目描述: 1015. Jill's Tour Paths Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Every ...
- R8:Learning paths for Data Science[continuous updating…]
Comprehensive learning path – Data Science in Python Journey from a Python noob to a Kaggler on Pyth ...
- [LeetCode] Binary Tree Paths 二叉树路径
Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...
- [LeetCode] Unique Paths II 不同的路径之二
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- [LeetCode] Unique Paths 不同的路径
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- leetcode : Binary Tree Paths
Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- LeetCode-62-Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- Leetcode Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
随机推荐
- 例题6-5 Boxes in a line uVa12657
这道题目的解决方案是双向链表,数据结构本身并不复杂,但对于四种情况的处理不够细致,主要体现在以下几点: 分类讨论不全面,没有考虑特殊情况(本身不需要操作,需要互换的两元素相邻) 没有考虑状态4改变后对 ...
- windows创建桌面快捷方式的VBA脚本
Dim wShell, oShortcut 'Dim strDesktop$ ' 为了与VBS兼容, Dim strDesktop ' 这里改写一下,测试通过... Set w ...
- 正确处理WPF中Slider值改变事件的方式
最近在用WPF数据绑定重写一下播放器项目时遇到的关于Slider的问题,在窗体透明度调节和播放进度调节上用了Slider控件.调节窗体透明度我是 这么想的:将窗体的Opacity属性的值与Slider ...
- MVC中System.InvalidOperationException: 传入字典的模型项的类型为“XXX”,但此字典需要类型“XXA”的模型项
出现此类错误的一个原因是Controller传过去的Model和View中的Model不是同一个Model
- Oracle物理的体系结构
体系结构图的学习: 老余服装店的故事 结构图: SQL查询语句 SGA 共享池shared pool 数据缓存区Buffer cache PGA 进程 SQL更新语句 SGA: 日志缓存区 日志文件 ...
- AVPlayer的基本使用
2014-5-7 06:46| 发布者: admin| 查看: 437| 评论: 0 摘要: 在iOS开发中,播放视频通常有两种方式,一种是使用MPMoviePlayerController(需要 ...
- android之TextView
TextView 常用属性说明: lines:设置可以显示的文本行数,且不管文本是否足够占用这些行的空间,该组件都会占用这些行的空间高度. maxLines:设置最大显示的行数,随文本改变,占用的行数 ...
- centos wordpress
How To Install Linux, nginx, MySQL, PHP (LEMP) stack on CentOS 6 https://www.digitalocean.com/commun ...
- GitHub error “Failed to get HEAD”
cd /要提交的文件的文件夹下 比如要提交一个名为 demo的 程序, 那么先进入demo 的文件夹里面 然后 进行以下两步 git init (有时这个是不必要的,因为xcode 自 ...
- 面试问到struts1与struts2的解析对比
一.struts1要继承一个抽象类.struts1是类编程而不是接口编程. struts2的action可以实现一个action接口,也可以实现其他的接口,使其成为可选的定制的服务. 二.struts ...