• 2015 Multi-University Training Contest 5 hdu 5349 MZL's simple problem


    MZL's simple problem

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


    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
     
    Source
     
    解题:由于我们只需要查询最大值,所以最大值总是最后一个被删的,如果当前集合只有一个元素,那么肯定是删最大的元素了,否则,随便删就是了,不影响最大值
     
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 int main() {
     4     int n,op,val;
     5     while(~scanf("%d",&n)) {
     6         int sz = 0,maxval = INT_MIN;
     7         while(n--) {
     8             scanf("%d",&op);
     9             switch(op) {
    10             case 1:
    11                 scanf("%d",&val);
    12                 maxval = max(val,maxval);
    13                 sz++;
    14                 break;
    15             case 2:
    16                 sz = max(0,sz-1);
    17                 if(!sz) maxval = INT_MIN;
    18                 break;
    19             case 3:
    20                 printf("%d
    ",sz?maxval:0);
    21                 break;
    22             default:
    23                 ;
    24             }
    25         }
    26     }
    27     return 0;
    28 }
    View Code
  • 相关阅读:
    B树与B+详解
    SQLite占用资源少原因
    iOS SQLite详解
    YTKNetwork网络封装
    YTKNetwork源码详解
    AFNetworking封装-项目使用
    iOS网络请求-AFNetworking源码解析
    PHP 不使用第三个变量实现交换两个变量的值
    PHP public private protected 三种修饰符的区别
    PHP 汉字转拼音
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4704600.html
Copyright © 2020-2023  润新知