zoukankan      html  css  js  c++  java
  • POJ 1442 Black Box

      优先队列水过~~~

      

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstdio>
     4 #include <cstring>
     5 #include <cmath>
     6 #include <cstdlib>
     7 #include <queue>
     8 
     9 using namespace std;
    10 
    11 int seq[30010];
    12 
    13 int main()
    14 {
    15     int n,m,i,j,order,top,lastorder;
    16 
    17     while(scanf("%d %d",&m,&n) != EOF)
    18     {
    19 
    20         priority_queue<int> q1;
    21         priority_queue<int ,vector<int>,greater<int> > q2;
    22 
    23         for(i = 0; i < m; ++i)
    24             scanf("%d",&seq[i]);
    25 
    26         lastorder = 0;
    27 
    28         top = 0;
    29 
    30         for(i = 0; i < n; ++i)
    31         {
    32             scanf("%d",&order);
    33 
    34             for(j = lastorder; j < order; ++j)
    35             {
    36                 if(top < i+1)
    37                 {
    38                     q1.push(seq[j]);
    39                     ++top;
    40                 }
    41                 else
    42                 {
    43                     q2.push(seq[j]);
    44                 }
    45             }
    46 
    47             lastorder = order;
    48 
    49             while(top < i+1)
    50             {
    51                 ++top;
    52                 q1.push(q2.top());
    53                 q2.pop();
    54             }
    55 
    56 
    57             while(!q1.empty() && !q2.empty() && q1.top() > q2.top())
    58             {
    59                 q1.push(q2.top());
    60                 q2.push(q1.top());
    61                 q1.pop();
    62                 q2.pop();
    63             }
    64             printf("%d
    ",q1.top());
    65         }
    66     }
    67     return 0;
    68 }
    View Code
  • 相关阅读:
    复制表结构及数据
    mysql 字段名是关键字 报错
    mysql 截取字符串
    《官方资料》 例如:string 函数 、分组函数
    mysql event 入门
    Spring国际化
    Python学习记录
    精选股文
    为VS定制一个自己的代码生成器
    房产常识
  • 原文地址:https://www.cnblogs.com/zmx354/p/3267342.html
Copyright © 2011-2022 走看看