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. WindowsMediaPlayer控件批量添加文件至播放列表

    思路: 1.读取批定路径的目录文件. 2.用List存放. 3.循环List列表添加到播放列表. public void VidieoPlay() { //WindowsMediaPlayer1.ui ...

  2. vc列表控件的初始化

    void CManageProcessDlg::InitList() {  m_ListProcess.SetExtendedStyle(m_ListProcess.GetExtendedStyle( ...

  3. 将Unity3D游戏移植到Android平台上

    将Unity3D游戏移植到Android平台是一件很容易的事情,只需要在File->Build Settings中选择Android平台,然后点击Switch Platform并Build出ap ...

  4. HDU 1465 第六周L题

    Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了!  做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样.  ...

  5. atomic_read

    static inline int atomic_read(const atomic_t *v) { return (*(volatile int *)&(v)->counter); } ...

  6. 【转载】MySQL被慢sql hang住了,用shell脚本快速清除不断增长的慢sql的办法

    原文地址:MySQL被慢sql hang住了,用shell脚本快速清除不断增长的慢sql的办法 作者:mchdba 某个初级dba误删index,mysql漫山遍野全是10S以上的慢sql,mysql ...

  7. c++中new分配动态数组

    变长一维数组     这里说的变长数组是指在编译时不能确定数组长度,程序在运行时需要动态分配内存空间的数组.实现变长数组最简单的是变长一维数组,你可以这样做:  //文件名: array01.cpp ...

  8. http概述

    HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990年提出,经过几年的使用与发展,得到不断地完善和扩展.目前在WWW中使用的是HTTP/1.0的第 ...

  9. 【F#】核心数据多线程处理的首选

    http://www.cnblogs.com/zilin-xiao/archive/2011/08/26/2155124.html

  10. centos Supervisor

    Supervisor是一个进程监控程序. 满足的需求是:我现在有一个进程需要每时每刻不断的跑,但是这个进程又有可能由于各种原因有可能中断.当进程中断的时候我希望能自动重新启动它,此时,我就需要使用到了 ...