zoukankan      html  css  js  c++  java
  • C

    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).

    输出第k大的数字,优先队列水题

    #include<iostream>
    #include<stdio.h>
    #include<stdlib.h>
    #include <iomanip>
    #include<cmath>
    #include<float.h> 
    #include<string.h>
    #include<algorithm>
    #define sf scanf
    #define pf printf
    #define scf(x) scanf("%d",&x)
    #define scff(x,y) scanf("%d%d",&x,&y)
    #define prf(x) printf("%d
    ",x) 
    #define mm(x,b) memset((x),(b),sizeof(x))
    #include<vector>
    #include<queue>
    #include<map>
    #define rep(i,a,n) for (int i=a;i<n;i++)
    #define per(i,a,n) for (int i=a;i>=n;i--)
    typedef long long ll;
    const ll mod=1e9+7;
    const double eps=1e-8;
    const int inf=0x3f3f3f3f;
    using namespace std;
    const double pi=acos(-1.0);
    const int N=3e2+10;
    priority_queue<int> q1;
    priority_queue<int,vector<int>,greater<int> > q2;
    void del()
    {
    	while(!q2.empty())
    	q2.pop();
    }
    int main()
    {
    	int n,x,k;
    	char c;
    	while(~scff(n,k))
    	{
    		del();
    		while(n--)
    		{
    			getchar(); 
    			sf("%c",&c);
    			if(c=='I')
    			{
    				scf(x);
    				q2.push(x);
    				if(q2.size()>k)
    				q2.pop(); 
    			}else
    			prf(q2.top());
    		}
    	 } 
    	return 0;
    }
    
  • 相关阅读:
    第十五篇 -- 学习第十四天打卡20190702
    第三篇 -- 方向
    第十四篇 -- 学习第十三天打卡20190701
    yum更换阿里源
    Jenkins+sonar7.3集成
    xshell 5 书写汉字乱码
    zabbix 短信报警
    zabbix 微信报警
    zabbix邮件报警
    zabbix主动监测客户端设置
  • 原文地址:https://www.cnblogs.com/wzl19981116/p/9498310.html
Copyright © 2011-2022 走看看