zoukankan      html  css  js  c++  java
  • 2015 Multi-University Training Contest 5 1007

    MZL's simple problem

    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 0    Accepted Submission(s): 0


    Problem Description
    A simple problem
    Problem Description
    You have a multiple set,and now there are three kinds of operations:
    1 x : add number x to set
    2 : delete the minimum number (if the set is empty now,then ignore it)
    3 : query the maximum number (if the set is empty now,the answer is 0)
     
    Input
    The first line contains a number N (N106),representing the number of operations.
    Next N line ,each line contains one or two numbers,describe one operation.
    The number in this set is not greater than 109.
     
    Output
    For each operation 3,output a line representing the answer.
     
    Sample Input
    6
    1 2
    1 3
    3
    1 3
    1 4
    3
     
    Sample Output
    3
    4
     
    题意:三种对集合的操作:1、加入一个数 2、删除最小值 3、求最大值
    分析:加入时,维护最大值,删除时如果集合为空,则定义最大值为无穷小
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<string>
    #include<iostream>
    #include<cstring>
    #include<cmath>
    #include<stack>
    #include<queue>
    #include<vector>
    #include<map>
    #include<stdlib.h>
    #include<algorithm>
    #define LL __int64
    using namespace std;
    const int INF=0x3f3f3f3f;
    int n;
    int main()
    {
        while(scanf("%d",&n)!=EOF)
        {
            int opt,x;
            int maxn=-INF;
            int f=0,r=0;
            for(int i=0;i<n;i++)
            {
                scanf("%d",&opt);
                if(opt==1)
                {
                    scanf("%d",&x);
                    r++;
                    if(x>maxn) maxn=x;
                }
                if(opt==2)
                {
                    if(f<r) f++;
                    if(f==r) maxn=-INF;
                }
                if(opt==3)
                {
                    if(f==r) printf("0
    ");
                    else printf("%d
    ",maxn);
                }
            }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    C程序的存储空间布局
    获取系统数据文件信息
    基于UDP的一对回射客户/服务器程序
    一段经典的 Java 风格程序 ( 类,包 )
    Vue 脱坑记
    vue面试题总汇
    JavaScript调试技巧
    伪元素小技巧
    JavaScript 开发人员需要知道的简写技巧
    select2插件改造之设置自定义选项 源码
  • 原文地址:https://www.cnblogs.com/clliff/p/4703308.html
Copyright © 2011-2022 走看看