10474:Where is the Marble?

原创 2018年04月15日 13:19:26

Where is the Marble?


排序加二分查找

#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 100000;
int n,q,mar[maxn];
int main(){
    int kase = 0;
    while(scanf("%d%d",&n,&q) == 2 && n){
        for(int i = 0;i < n;i++) scanf("%d",mar[i]);
        sort(mar,mar + n);
        printf("CASE# %d:\n",++kase);
        int qnum,p;
        while(q--){
            scanf("%d",&qnum);
            p = lower_bound(mar,mar + n) - mar;
            if(a[p] == pnum) printf("%d is found at %d\n",p);//二分查找 不是 p == n
            else printf("%d not found\n",pnum);
        }
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37754288/article/details/79948529

UVa 10474 Where is the Marble?(大理石在哪儿)

UVa 10474 Where is the Marble?(大理石在哪儿) UVa题目链接 题目名称:大理石在哪 题目描述: 现有N个大理石,每个大理石上写了一个非负整数,首先把各数从小到大...
  • u010555622
  • u010555622
  • 2014-07-03 01:52:47
  • 831

UVA 10474 Where is the Marble? (STL最简单运用)

Where is the Marble?   Description Raju and Meena love to play with Marbles. They have got a lot...
  • hurmishine
  • hurmishine
  • 2016-05-16 22:59:18
  • 4085

UVA10474 Where is the Marble?【排序】

Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on the...
  • tigerisland45
  • tigerisland45
  • 2016-08-02 22:40:07
  • 946

UVa 10474 Where is the Marble? (二分查找&equal_range()的使用)

10474 - Where is the Marble? Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=c...
  • synapse7
  • synapse7
  • 2013-10-16 14:10:06
  • 866

C++ lower_bound 算法竞赛 例5-1 大理石在哪儿(UVa 10474)

lower_bound查找大于或等于x的第一个位置。 输入n个大理石,q个问题;每个问题问是否有一个大理石写着整数x,如果有回答是哪个 【样列输入】 4 1 2 3 5 1 ...
  • zhaohaibo_
  • zhaohaibo_
  • 2018-02-03 00:14:01
  • 23

uva 10474 Where is the Marble?(二分STL)

题意很简单,找到排序后的
  • u013508213
  • u013508213
  • 2014-07-01 13:43:34
  • 264

UVA ~ 10474 ~ Where is the Marble? (二分)

题意:现在有N个大理石,每个大历史上写了一个非负整数。首先把各数从小到大排序,然后回答Q个问题。每个问题问是否有一个大理石写着某个整数x,如果是,还要回答哪个大理石上写着x。排序后所有的大理石从上到下...
  • ZscDst
  • ZscDst
  • 2017-12-29 15:39:14
  • 159

UVA 10474 --- Where is the Marble? 二分查找

Where is the Marble? Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Subm...
  • u013014691
  • u013014691
  • 2014-12-21 17:45:44
  • 500

UVa_10474 - Where is the Marble?

很简单的思路,将大理石的number
  • wowowoc
  • wowowoc
  • 2014-06-24 20:16:50
  • 301

算法竞赛入门经典第五章例题5-1 Where is the Marble? UVA - 10474

https://vjudge.net/problem/UVA-10474 #include #include #pragma warning(disable:4996) using namespac...
  • Bendaai
  • Bendaai
  • 2018-01-06 21:58:42
  • 408
收藏助手
不良信息举报
您举报文章:10474:Where is the Marble?
举报原因:
原因补充:

(最多只允许输入30个字)