武大OJ 574. K-th smallest
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的更多相关文章
- 华农oj Problem K: 负2进制【有技巧构造/待补】
Problem K: 负2进制 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 51 Solved: 6 [Submit][Status][Web Boa ...
- 武大OJ 706.Farm
Farmer John has a farm. Betsy, a famous cow, loves running in farmer John's land. The noise she made ...
- Leetcode OJ : Merge k Sorted Lists 归并排序+最小堆 mergesort heap C++ solution
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode ...
- 武大OJ 622. Symmetrical
Description Cyy likes something symmetrical, and Han Move likes something circular. Han Mov ...
- 武大OJ 613. Count in Sama’s triangle
Description Today, the math teacher taught Alice Hui Yang’s triangle. However, the teacher came up w ...
- 武大OJ 612. Catch the sheep
Description Old Sama is a great and powerful magician in the word. One day, a little girl, Anny, tou ...
- [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 ...
- [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 ...
- [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 ...
随机推荐
- Linux之线程相关命令及常用命令
查进程 top命令:查看系统的资源状况.#top top -d 10 //指定系统更新进程的时间为10秒 ps:查看当前用户的活动进程.#ps -A ps命令查找与进程相关的PID号: ps ...
- python 中 str与bytes的转换
# bytes转字符串方式一 b=b'\xe9\x80\x86\xe7\x81\xab' string=str(b,'utf-8') print(string) # bytes转字符串方式二 b=b' ...
- Hdu 3487 play the chain
Description 瑶瑶很喜欢玩项链,她有一根项链上面有很多宝石,宝石从1到n编号. 首先,项链上的宝石的编号组成一个序列:1,2,3,...,n. 她喜欢两种操作: 1.CUT a b c:他会 ...
- Android 性能优化(9)网络优化( 5)Optimizing Server-Initiated Network Use
Optimizing Server-Initiated Network Use This lesson teaches you to Send Server Updates with GCM Netw ...
- C#手机充值系统开发(基于聚合数据)
说是手机充值系统有点装了,其实就是调用了聚合数据的支付接口,其实挺简单的事 但是我发现博客园竟然没有类似文章,我就个出头鸟把我的代码贡献出来吧 首先说准备工作: 去聚合数据申请账号-添加手机支付的认证 ...
- 解决FormClosing事件点击关闭2次的问题
以下代码:提示框会跳出2遍 private void mFrmmain_FormClosing(object sender, FormClosingEventArgs e) { if (Dialog ...
- TCP/IP和UDP的比较
TCP.UDP详解 1.传输层存在的必要性 由于网络层的分组传输是不可靠的,无法了解数据到达终点的时间,无法了解数据未达终点的状态.因此有必要增强网络层提供服务的服务质量. 2.引入传输层的原因 面向 ...
- [Windows Server 2008] MySQL单数据库迁移方法
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:MySQL ...
- 给一个链表,若其中包含环,请找出该链表的环的入口结点,否则,输出null。
package algorithms; /* 给一个链表,若其中包含环,请找出该链表的环的入口结点,否则,输出null. public class ListNode { int val; ListNo ...
- docker 1-->docker swarm 转载
实践中会发现,生产环境中使用单个 Docker 节点是远远不够的,搭建 Docker 集群势在必行.然而,面对 Kubernetes, Mesos 以及 Swarm 等众多容器集群系统,我们该如何选择 ...