zoukankan      html  css  js  c++  java
  • UVA 10474 Where is the Marble?

          主要利用题目中的条件,并不需要排序。因为出现的数不超过10000。只需要统计0 - 10000出现数的个数,就可以确定出现数的排名。

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    int main() {
        int n, q;
        int que[10005];
    
        int count = 1;
        while (scanf("%d%d", &n, &q) && n && q) {
            memset(que, 0, sizeof (que));
    
            int maxn = 0, tmp;
            for (int i=0; i<n; i++) {
                scanf("%d", &tmp);
                que[tmp]++;
                maxn = maxn < tmp ? tmp : maxn; // 记录下出现的最大数
            }
            tmp = 0;
            for (int i=0; i<=maxn; i++) {
                if (que[i]) {
                    tmp += que[i];
                    que[i] = tmp-que[i]+1;
                }
            }
    
            printf("CASE# %d:\n", count++);
            for (int i=0; i<q; i++) {
                scanf("%d", &tmp);
                if (que[tmp]) {
                    printf("%d found at %d\n", tmp, que[tmp]);
                }
                else {
                    printf("%d not found\n", tmp);
                }
            }
    
        }
    
        return 0;
    }
    


     

  • 相关阅读:
    CF293E Close Vertice
    [SCOI2016]幸运数字
    [NOI2003]逃学的小孩
    0302读后感
    1231递归下降语法分析
    1210-有穷自动机
    11.12 评论汇总
    1029语言文法
    0921 词法分析
    0909开启编译原理之路
  • 原文地址:https://www.cnblogs.com/zcube/p/4194557.html
Copyright © 2011-2022 走看看