zoukankan      html  css  js  c++  java
  • CSUOJ 1554 SG Value

    1554: SG Value

    Time Limit: 5 Sec  Memory Limit: 256 MB
    Submit: 140  Solved: 35

    Description

    The SG value of a set (multiset) is the minimum positive integer that could not be constituted of the number in this set.
    You will be start with an empty set, now there are two opertions:
    1. insert a number x into the set;
    2. query the SG value of current set.

    Input

    Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1e5) -- the total number of opertions.
    The next N lines contain one opertion each.
    1 x means insert a namber x into the set;
    2 means query the SG value of current set.

    Output

    For each query output the SG value of current set.

    Sample Input

    5
    2
    1 1
    2
    1 1
    2

    Sample Output

    1
    2
    3

    HINT

     

    Source

    解题:答案爆INT啊。。。注意溢出

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 priority_queue<int,vector<int>,greater<int> >q;
     5 int n,op;
     6 int main(){
     7     while(~scanf("%d",&n)){
     8         while(!q.empty()) q.pop();
     9         LL ans = 0;
    10         while(n--){
    11             scanf("%d",&op);
    12             if(op == 1){
    13                 scanf("%d",&op);
    14                 q.push(op);
    15             }else{
    16                 while(!q.empty() && q.top() <= ans + 1){
    17                     ans += q.top();
    18                     q.pop();
    19                 }
    20                 printf("%lld
    ",ans+1);
    21             }
    22         }
    23     }
    24     return 0;
    25 }
    View Code
  • 相关阅读:
    javascript零散要点收集
    javascript闭包,arguments和prototype
    javascript面向对象规则汇总以及json
    递归转非递归的编程思想
    汇编要点汇总
    队列相关算法
    深度优先遍历算法
    C++面向对象要点
    堆排序
    快速排序算法
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4385452.html
Copyright © 2011-2022 走看看