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. Java对象简单实用(计算器案例)

    对 Java中的对象与属性,方法的使用,简单写了个案例 import java.util.Scanner; class Calculste { int a; //定义两个整数 int b; Strin ...

  2. Hadoop的数据采集框架

    问题导读: Hadoop数据采集框架都有哪些? Hadoop数据采集框架异同及适用场景? Hadoop提供了一个高度容错的分布式存储系统,帮助我们实现集中式的数据分析和数据共享.在日常应用中我们比如要 ...

  3. CF822C Hacker, pack your bags!

    思路: 对于一个区间[l, r],只需枚举所有满足r' < l并且二者duration之和为x的区间[l', r'],寻找其中二者cost之和最小的即可.于是可以开一个数组a[],a[i]表示所 ...

  4. android视频播放器系列(二)——VideoView

    最近在学习视频相关的知识,现在也是在按部就班的一步步的来,如果有同样需求的同学可以跟着大家一起促进学习. 上一节说到了可以使用系统播放器以及浏览器播放本地以及网络视频,但是这在很大程度上并不能满足我们 ...

  5. Server 2008 R2 事件查看器实现日志分析

    在 windows server 2008 R2 中,可以通过点击 "开始" -> "管理工具" -> "事件查看器" ,来打开 ...

  6. java继承问题

    代码: 父类: public class Father { public Father() { System.out.println("基类构造函数{"); show(); new ...

  7. JMeter在linux上分布式压测遇到的坑(三)

    master和slave机要在同一网段内,才能做分布式(Jmeter要配环境变量,这样不用手动起server) 分布式不成功,解决方案: 1.master端和slave端要ping通 2.ping通后 ...

  8. nginx_rewrite规则介绍

    rewrite功能就是,使用nginx提供的全局变量或自己设置的变量,结合正则表达式和标志位实现url重写以及重定向.rewrite只能放在server{},location{},if{}中,并且只能 ...

  9. Java基础(六)--枚举Enum

    枚举: 刚开始项目中没怎么用过,只知道能够实现作为项目中类似定义Constant的功能,然后知道枚举实现的单例模式几乎是最优雅的,所以, 想要深入完整的了解一下 1.基本特性: Enum.values ...

  10. Python之实例属性和类属性

    参考原文 廖雪峰Python 实例属性和类属性 在前面已经说过由于Python是动态语言,可以根据类的实例绑定任何的属性. 给实例绑定属性的方法是通过实例变量,或者self变量绑定的: class S ...