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的更多相关文章

  1. soj 1015 Jill's Tour Paths 解题报告

    题目描述: 1015. Jill's Tour Paths Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Every ...

  2. 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 ...

  3. [LeetCode] Binary Tree Paths 二叉树路径

    Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...

  4. [LeetCode] Unique Paths II 不同的路径之二

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  5. [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 ...

  6. leetcode : Binary Tree Paths

    Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...

  7. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  8. 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 ...

  9. Leetcode Unique Paths II

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

随机推荐

  1. Java包的命名规则

    按照惯例,包申明遵循特定的格式.虽然不是严格要求的Java语法,如果不遵循格式要求,大多数的Java认为你是不懂Java. 从右到左的顺序是: 1.systaxExample表明包的本地名称. 2.e ...

  2. asp.net图片上传实例

    网站后台都需要有上传图片的功能,下面的例子就是实现有关图片上传. 缺点:图片上传到本服务器上,不适合大量图片上传. 第一.图片上传,代码如下: xxx.aspx 复制代码代码如下: <td cl ...

  3. Zendframework 模块加载事件触发顺序。

    模块加载时事件触发的时间顺序: 0.loadModules(ModuleEvent::EVENT_LOAD_MODULES) 1.  loadModule.resolve(ModuleEvent::E ...

  4. oracle11g RAC添加节点

    OS: [root@rac ~]# more /etc/oracle-releaseOracle Linux Server release 5.7 DB: SQL> SELECT * FROM ...

  5. ASP.NET 运行机制

    原本今天打算继续写ASP.NET MVC第四天的.但是由于里面涉及到asp.net运行机制的原理,如果不分析一下这里,mvc想说清楚还是挺困难的.既然要提到asp.net运行机制,所以打算还是说详细一 ...

  6. [分享] Code::Blocks Windows Console 中文亂碼解決

    相信各位大大們應該都有聽過Code::Blocks這個IDE,但網路上有許多人反應Code::Blocks不能編出中文的Console程式,但 Code::Blocks最新的版本預設使用UTF-8做為 ...

  7. Careercup - Google面试题 - 5732809947742208

    2014-05-03 22:10 题目链接 原题: Given a dictionary, and a list of letters ( or consider as a string), find ...

  8. [algothrim]URL相似度计算的思考

    http://www.spongeliu.com/399.html http://in.sdo.com/?p=865

  9. C#中类型分析中的常见问题 Type - 转

    http://www.cnblogs.com/yuanyuan/archive/2012/08/16/2642281.html 写代码的时候经常需要分析已有类型的信息例如:分析现有类型自动生成类, 或 ...

  10. 【转】在RedHat上搭建自己Email服务器

    原文:http://6839976.blog.51cto.com/6829976/1323482 by LN__@linux 目前邮件服务器中,想要拥有自己的邮件服务器,单单使用senmail,pos ...