武大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 ...
随机推荐
- httpd 安装ssl证书
1) 安装ssl模块 # yum install mod_ssl -y Ps:安装完成后,会在/etc/httpd/conf.d/下生成一个ssl.conf配置文件. 2) 先建一个目录用来放ssl证 ...
- spring cxf 配置步骤
spring 项目增加web service的步骤:1.复制cxf的jar包2.web.xml配置cxf的核心控制器:org.apache.cxf.transport.servlet.CXFServl ...
- 对路径 obj 文件夹访问被拒绝
TFS 刚下载的项目,出现该问题. 解决方案: 将文件夹属性“只读”,取消
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem
Let SS be a sequence of integers s_{1}s1, s_{2}s2, ......, s_{n}snEach integer is is associ ...
- TimeOut Error :因为远程服务器关闭导致mnist数据集不能通过input_data下载下来
解决办法: 修改文件: C:\Users\501-PC\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\con ...
- [ CodeForces 1064 B ] Equations of Mathematical Magic
\(\\\) \(Description\) \(T\) 组询问,每次给出一个 \(a\),求方程 \[ a-(a\oplus x)-x=0 \] 的方案数. \(T\le 10^3,a\le 2^{ ...
- HTML meta信息含义
<meta name="viewport" content="width=device-width,initial-scale=1.0"> cont ...
- 模块挂载、切换,uml模式、流程图模式
模块挂载.切换,uml模式.流程图模式
- Flask框架 之request对象
一.request对象属性 属性 说明 类型 data 记录请求的数据,并转换为字符串 * form 记录请求中的表单数据 MultiDict args 记录请求中的查询参数 MultiDict co ...
- VR虚拟红包的技术实现
2017年1月20日,腾讯发布消息称将推出Q-Glass,除了一般VR眼镜的标配功能外,Q-Glass还能实现眨眼抢红包.听起来是不是很酷炫?上市时间可要在10年后.不过,2016年底支付宝首推AR实 ...