美文网首页
Where is the Marble? UVA - 10474

Where is the Marble? UVA - 10474

作者: HeoLis | 来源:发表于2019-02-11 16:35 被阅读17次

https://vjudge.net/problem/UVA-10474

#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    const int maxn = 10000;
    int n, q, x, kase = 0;
    int num[maxn];

    while (scanf("%d%d", &n, &q) == 2 && n) {
        printf("CASE# %d:\n", ++kase);
        for (int i = 0; i < n; ++i)
            scanf("%d", &num[i]);
        sort(num, num + n); // 排序
        while (q--) {
            scanf("%d", &x);
            int p = lower_bound(num, num + n, x) - num; // 在已排序数组num中寻找x
            if (num[p] == x)
                printf("%d found at %d\n", x, p + 1);
            else
                printf("%d not found\n", x);
        }
    }
    return 0;
}

lower_bound函数查找“大于等于x的第一个位置”

int p = lower_bound(num, num + n, x) - num; // 在已排序数组num中寻找x

sort(v.begin, v.end())排序

相关文章

  • UVA 10474 Where is the Marble?

    Problem https://uva.onlinejudge.org/external/104/10474.pd...

  • Where is the Marble? UVA - 10474

    https://vjudge.net/problem/UVA-10474 lower_bound函数查找“大于等于...

  • 10474 - Where is the Marble?

    输入乱序的一些数,先从小到大排序后再查询某个数是否在这个数列中,在则输出其位置。读入数据后先快排再二分查找,但是相...

  • 50190224牙套第一天

    花费:10474 好贵啊

  • Marble - Restful API

    Marble JOB 支持http方式的调度和结果查询。具体如下 >> Marble JOB启动(HTTP方式):...

  • 18.5.17 一些文字

    the blue marble & the black marble 心脏有点痒痒的,那是一种让人忍不住咬着下唇的...

  • 素数练习题

    UVA 10375 UVA 10791 UVA10375 Choose and divide 题解 先素数打表,然...

  • Marble Shooter Blast

    An addictive marble shooter game! Challenge the darkness ...

  • Marble 运行

    Marble 项目运行 1 数据库建立 本地新建一个数据库。从源代码的document目录下copy文件marbl...

  • 有趣的数学题

    UVA12716 UVA11582 UVA12716 GCD XOR 题解 参考这题用到2个结论a ^ b = c...

网友评论

      本文标题:Where is the Marble? UVA - 10474

      本文链接:https://www.haomeiwen.com/subject/qwbqeqtx.html