The kth great number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 6121    Accepted Submission(s): 2471
Problem Description
Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask Xiao Bao what the kth great number is. Because the number written by Xiao Ming is too much, Xiao Bao is feeling giddy. Now, try to help Xiao Bao.
 
Input
There are several test cases. For each test case, the first line of input contains two positive integer n, k. Then n lines follow. If Xiao Ming choose to write down a number, there will be an " I" followed by a number that Xiao Ming will write down. If Xiao Ming choose to ask Xiao Bao, there will be a "Q", then you need to output the kth great number. 
 
Output
The output consists of one integer representing the largest number of islands that all lie on one line. 
 
Sample Input
8 3
I 1
I 2
I 3
Q
I 5
Q
I 4
Q
 
Sample Output
1
2
3

Hint

Xiao Ming won't ask Xiao Bao the kth great number when the number of the written number is smaller than k. (1=<k<=n<=1000000).

 
Source
 
 
解题思路: 
  我的想法就是,既然是要求第 k 大的数字,我就是设一数组总长度为k,其中最小的元素值即为第k大的数
  不需要优先队列 或者是 线段树、红黑树等一些高级数据结构就能写出来的一题。
 
 
我的代码:
 #include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int b[];
int main(){
int i,j,t,n,k,num,flag_t,min,flag;
char c;
while(EOF != scanf("%d%d",&n,&k)){
flag_t = ;
min = ;
while(n--){
getchar();
scanf("%c",&c);
if(c == 'I'){
scanf("%d",&num);
if(flag_t < k){
b[flag_t] = num;
if(num < min){
min = num;
flag = flag_t;
}
flag_t++;
}
else if(num > min){
b[flag] = num;
min = ;
for(i=;i<k;i++){
if(b[i] < min){
min = b[i];
flag = i;
}
}
}
}
else if(c == 'Q'){
printf("%d\n",min);
}
}
}
return ;
}

HDOJ4006 The kth great number 【串的更改和维护】的更多相关文章

  1. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  2. [LintCode] Kth Smallest Number in Sorted Matrix 有序矩阵中第K小的数字

    Find the kth smallest number in at row and column sorted matrix. Have you met this question in a rea ...

  3. hdu 4006 The kth great number (优先队列)

    /********************************************************** 题目: The kth great number(HDU 4006) 链接: h ...

  4. Lintcode: Kth Smallest Number in Sorted Matrix

    Find the kth smallest number in at row and column sorted matrix. Example Given k = 4 and a matrix: [ ...

  5. hdoj 4006 The kth great number【优先队列】

    The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Oth ...

  6. The kth great number(set)

    The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Oth ...

  7. The kth great number(优先队列)

    The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Oth ...

  8. HDU 4006 The kth great number 优先队列、平衡树模板题(SBT)

    The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Oth ...

  9. [LeetCode] Kth Smallest Number in Multiplication Table 乘法表中的第K小的数字

    Nearly every one have used the Multiplication Table. But could you find out the k-th smallest number ...

随机推荐

  1. iOS开展-CocoaPods安装和使用教程

    原文链接: iOS开展-CocoaPods安装和使用教程 修正已经增加了自己的理解. CocoaPods安装和使用教程 Code4App 原创文章.转载请注明出处:http://code4app.co ...

  2. Ext JS学习第八天 Ext基础之 认识Ext.js 和Ext-more.js

    此文来记录学习笔记: •认识Ext.js 和Ext-more.js •首先,我们要知道这2个js文件的作用,这俩个文件包含了Ext的一些基础定义.基本的属性和方法,我们要重点学习和深入底层代码进行研究 ...

  3. 浅谈PHP技术应用

    序号:1210-41 黑龙江省高等教育自学考试 本科毕业论文 题    目    浅谈PHP技术 学员姓名    夏滟 专    业    计算机及应用 准考证号    010311192585 指导 ...

  4. Asp.Net MVC4.0 官方教程 入门指南之四--添加一个模型

    Asp.Net MVC4.0 官方教程 入门指南之四--添加一个模型 在这一节中,你将添加用于管理数据库中电影的类.这些类是ASP.NET MVC应用程序的模型部分. 你将使用.NET Framewo ...

  5. Hive环境搭建心得(Ubuntu)

    Hive是什么? 基于Hadoop的数据查询工具,可以使用类SQL进行数据查询. Hadoop安装 参考了Hadoop安装 注意到etc/hadoop/hadoop-env.sh里设置JAVA_HOM ...

  6. iOS 滤镜 转载,原文见正文首行链接

    转载自:http://blog.sina.com.cn/s/blog_5fb39f9101018gv7.html 直接上代码了: // // ViewController.m // 图片模糊处理 // ...

  7. bootstrap基础知识点YI

    <!DOCTYPE html> <html lang="en"> ... </html> bootstrap页面都应该包含html5声明. 框架 ...

  8. Django : Table 'MyDjango.django_admin_log' doesn't exist

    原因: 添加admin之后,没有运行 manage.py syncdb 解决方法: 在命令行中运行manage.py syncdb 即可 运行截图:

  9. Delphi 中 COM 实现研究手记(一)

    前言 前些日子用 Delphi 写了一个 Windows 外壳扩展程序,大家知道 Windows 外壳扩展实际上就是 COM 的一种应用 -- Shell COM,虽然整个程序写得还算比较顺利,但写完 ...

  10. 数据切分——MySql表分区概述

    定义:         表的分区指根据可以设置为任意大小的规则,跨文件系统分配单个表的多个部分.实际上,表的不同部分在不同的位置被存储为单独的表.用户所选择的.实现数据分割的规则被称为分区函数,这在M ...