zoukankan      html  css  js  c++  java
  • poj 3125 Printer Queue(STL注意事项)

    http://poj.org/problem?id=3125

      这道题没什么突出的地方,是一道很水的题,可以用list,也可以用queue来解决。(用list解决的代码我就不写了)把它写上来,只是因为我在使用STL的时候犯了一个小错误,从而导致我WA了数次。还是一个老问题,初始化。数组的使用需要初始化,STL的使用有时也要初始化。

      还是直接贴代码吧……

    View Code
     1 #include "cstdio"
     2 #include "cstdlib"
     3 #include "cstring"
     4 #include "cmath"
     5 #include "cctype"
     6 #include "vector"
     7 #include "list"
     8 #include "set"
     9 #include "map"
    10 #include "string"
    11 #include "algorithm"
    12 #include "stack"
    13 #include "queue"
    14 
    15 #define INF 0x7fffffff
    16 #define reset(a) memset(a, 0, sizeof(a))
    17 #define copy(a, b) memcpy(a, b, sizeof(b))
    18 #define PI acos(-1)
    19 #define FMAX (1E300)
    20 #define MAX 1000000000
    21 #define feq(a, b) (fabs((a)-(b))<1E-6)
    22 #define flq(a, b) ((a)<(b)||feq(a, b))
    23 #define MAXN 10005
    24 #define BASE 137
    25 #define PASS puts("pass")
    26 
    27 using namespace std;
    28 
    29 struct Job{
    30     int pri;
    31     int pos;
    32 };
    33 
    34 int main(){
    35     queue<Job> q;
    36     int exist[10];
    37     int T;
    38 
    39     scanf("%d", &T);
    40     while (T--){
    41         int n, m, p, tm = 0;
    42 
    43         reset(exist);
    44 /*****这部分是我起初忘记加上去的*****/
    45         while (!q.empty()){
    46             q.pop();
    47         }
    48 /******************************/
    49         scanf("%d%d", &n, &m);
    50         for (int i = 0; i < n; i++){
    51             Job t;
    52 
    53             scanf("%d", &t.pri);
    54             if (i == m){
    55                 p = t.pri;
    56             }
    57             t.pos = i;
    58             exist[t.pri]++;
    59             q.push(t);
    60         }
    61 
    62         int pri = 9;
    63 
    64         while (pri > p){
    65             while (exist[pri]){
    66                 if (q.front().pri == pri){
    67                     q.pop();
    68                     tm++;
    69                     exist[pri]--;
    70                 }
    71                 else {
    72                     q.push(q.front());
    73                     q.pop();
    74                 }
    75             }
    76             pri--;
    77         }
    78         //PASS;
    79         //printf("%d %d %d\n", q.front().pos, m, p);
    80         while (q.front().pos != m){
    81             if (q.front().pri == p) tm++;
    82             q.pop();
    83         }
    84         tm++;
    85         printf("%d\n", tm);
    86     }
    87 
    88     return 0;
    89 }

      好了,为的就只有这个。后面的路还长着,加油!

    P.S.:一个学习STL各容器用法的好网站,刚才发现的www.builder.com.cn/more/3_48.shtml

  • 相关阅读:
    C# 操作配置文件
    C# Excel操作类
    没有找到 mspdb100.dll 的解决办法
    工厂方法模式
    .Net互操作2
    The certificate used to sign “AppName” has either expired or has been revoked. An updated certificate is required to sign and install the application解决
    手机抓包xcode自带命令行工具配合wireshark实现
    expecting SSH2_MSG_KEX_ECDH_REPLY ssh_dispatch_run_fatal问题解决
    使用ssh-keygen设置ssh无密码登录
    远程复制文件到服务器
  • 原文地址:https://www.cnblogs.com/LyonLys/p/poj_3125_Lyon.html
Copyright © 2011-2022 走看看