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. python自动化测试学习笔记-7面向对象编程,类,继承,实例变量,邮件

    面向对象编程(OOP)术语: class TestClass(object):   val1 = 100       def __init__(self):     self.val2 = 200   ...

  2. MongoDB的用户权限管理

    1.创建用户并授权语法:db.createUser({user:"UserName",pwd:"Password",roles:[{role:"Rol ...

  3. [C陷阱和缺陷] 第3章 语义“陷阱”

    第3章 语义"陷阱"     一个句子哪怕其中的每个单词都拼写正确,而且语法也无懈可击,仍然可能有歧义或者并非书写者希望表达的意思.程序也有可能表面上是一个意思,而实际上的意思却相 ...

  4. Firebug

    Firebug是网页浏览器火狐下的一款开发类插件,它集HTML查看和编辑.JavaScript控制台.网络状态监视器于一体,是开发JavaScript.CSS.HTML和Ajax的得力助手.F12打开 ...

  5. 自学php【二】 PHP计算时间加一天

    最近几天在做一个项目,主要是将SQLserver数据到MySQL数据库,一个url跑一次 同步一次昨天的数据,由于很多数据需要同步,所以做了一个操作界面的,一个单纯跑url的 在其中涉及到了对于时间的 ...

  6. 并发编程学习笔记(13)----ConcurrentLinkedQueue(非阻塞队列)和BlockingQueue(阻塞队列)原理

    · 在并发编程中,我们有时候会需要使用到线程安全的队列,而在Java中如果我们需要实现队列可以有两种方式,一种是阻塞式队列.另一种是非阻塞式的队列,阻塞式队列采用锁来实现,而非阻塞式队列则是采用cas ...

  7. GC策略

           JVM里的GC(Garbage Collection)的算法有很多种,如标记清除收集器,压缩收集器,分代收集器等等,详见HotSpot VM GC 的种类 现在比较常用的是分代收集(ge ...

  8. python利用requests统计1个接口的响应时间

    参照 https://www.cnblogs.com/yoyoketang/p/8035428.html requests统计接口的响应时间有2种方式 r.elapsed.total_seconds( ...

  9. MFC获取各窗口指针句柄

    MFC在很多的对话框操作中,我们经常要用到在一个对话框中调用另一个对话框的函数或变量.可以用如下方法来解决.   HWND hWnd=::FindWindow(NULL,_T("Sphere ...

  10. 浅谈:nodejs在cmd提示不是内部或外部命令

    今天用cmd安装个库,结果发现node不是内部命令,检查后发现上次重装nodejs换了个安装位置,path环境变量忘改了. 找到变量值中node的安装地址,比如C:develop\nodejs,如果不 ...