Description

Give you a number S of length n,you can choose a position and remove the number on it.After that,you will get a new number.

More formally,you choose a number x(1<=x<=n),then you will get the number Rx=S1S2…..Sx-1 Sx+1……Sn..The problem is what number x you choose will get k-th smallest Rx of all R.

If there are more than one answer,choose smallest x.

Input

First line of each case contains two numbers n and k.(2 ≤ k≤  n ≤ 1 000 000).

Next line contains a number of length n. Each position corresponds to a number of 1-9.

Output

Output x on a single line for each case.

Sample Input

10 5
6228814462
10 4
9282777691

Sample Output

10
5 考虑123456543212345这种数字,就可以找到规律了
 #include<iostream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std; int n,k;
typedef struct{
int num,sum,firstX;
}Point;
Point p[]; int solve(int tot){
int i=;
while(i<=tot)
{
while(i<=tot&&p[i].num>p[i+].num)
{
k-=p[i].sum;
if(k<=)
{
return p[i].firstX;
}
p[i].sum=;
i++;
}
i++;
} for(i=tot;i>=;--i)
{
k-=p[i].sum;
if(k<=)
{
return p[i].firstX;
}
p[i].sum=;
}
return ; } int main()
{
p[].num=;
while(~scanf("%d %d",&n,&k))
{
char c;scanf("%c",&c);
int tot=;
for(int i=;i<=n;++i)
{
scanf("%c",&c);
if(p[tot].num==c-'')
{
p[tot].sum++;
}
else
{
tot++;
p[tot].num=c-'';
p[tot].sum=;
p[tot].firstX=i;
}
} // for(int i=1;i<=tot;++i)
// cout<<p[i].num<<" "<<p[i].sum<<" "<<p[i].firstX<<endl; cout<<solve(tot)<<endl; } }
												

武大OJ 574. K-th smallest的更多相关文章

  1. 华农oj Problem K: 负2进制【有技巧构造/待补】

    Problem K: 负2进制 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 51 Solved: 6 [Submit][Status][Web Boa ...

  2. 武大OJ 706.Farm

    Farmer John has a farm. Betsy, a famous cow, loves running in farmer John's land. The noise she made ...

  3. Leetcode OJ : Merge k Sorted Lists 归并排序+最小堆 mergesort heap C++ solution

    /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode ...

  4. 武大OJ 622. Symmetrical

    Description          Cyy likes something symmetrical, and Han Move likes something circular. Han Mov ...

  5. 武大OJ 613. Count in Sama’s triangle

    Description Today, the math teacher taught Alice Hui Yang’s triangle. However, the teacher came up w ...

  6. 武大OJ 612. Catch the sheep

    Description Old Sama is a great and powerful magician in the word. One day, a little girl, Anny, tou ...

  7. [LeetCode] K-th Smallest Prime Fraction 第K小的质分数

    A sorted list A contains 1, plus some number of primes.  Then, for every p < q in the list, we co ...

  8. [LeetCode] 786. K-th Smallest Prime Fraction 第K小的质分数

    A sorted list A contains 1, plus some number of primes.  Then, for every p < q in the list, we co ...

  9. [Swift]LeetCode786. 第 K 个最小的素数分数 | K-th Smallest Prime Fraction

    A sorted list A contains 1, plus some number of primes.  Then, for every p < q in the list, we co ...

随机推荐

  1. Glide和Picassio的比较

    http://blog.csdn.net/fancylovejava/article/details/44747759 对象池: Glide原理的核心是为bitmap维护一个对象池.对象池的主要目的是 ...

  2. C#中接受一个非字符串的输入

    接受来自用户的值 System 命名空间中的 Console 类提供了一个函数 ReadLine(),用于接收来自用户的输入,并把它存储到一个变量中. 例如: int num; num = Conve ...

  3. 实现div左右上下都居中

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. es6之数据结构 set,WeakSet,mapWeakMap

    { let list = new Set(); list.add(1); list.add(2); list.add(1); console.log(list); //Set(2) {1, 2} le ...

  5. Android APK瘦身之webp图片

    webp格式是谷歌推出的一种有损压缩格式,这种图片格式相比png或者jpg格式的图片损失的质量几乎可以忽略不计,但是压缩后图片的体积却比png或者jpg要小很多.亲测一个100kb的png图片经过we ...

  6. table的数据行tr上下移动

    昨天帮别人解决一个前端页面表格里的数据行上下移动的前端效果,直奔google找了几个demo,发现demo是实现了效果,但是代码很多,最后还是决定自己用jquery写个吧, 首先将前端效果分析出编程逻 ...

  7. 基于Crypto++的aes 字符串加解密实现

    esaes.h: #ifndef ESAES_H #define ESAES_H #include <cryptopp/aes.h> #include <iostream> # ...

  8. MFC_1.2 消息映射宏 数据绑定和交换

    消息映射宏 有三个主要的宏 类内声明 DECLARE_MESSAGE_MAP 表示使用消息映射 在CPP文件中使用 BEGIN_MESSAGE_MAP 和 END_MESSAGE_MAP 包含对应的消 ...

  9. 梦想CAD控件COM接口光栅图处理

    在CAD操作过程中,我们在设计绘图时,光栅图像也就是我们常说的图片,应用非常广泛,在CAD中可以直接插入光栅图像,并且可以对光栅图像进行裁剪.透明度调整等一些操作,在网页可以快速实现我们所需功能. 一 ...

  10. Redis系列(四)--持久化

    持久化就是将数据的更新异步的保存到磁盘中 持久化方式: 1.快照:某个时间点数据的备份 MySQL dump.Redis RDB 2.写日志:MySQL BinLog.HBASE Hlog.Redis ...