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

题目描述:算法竞赛入门经典例题5-1

 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4 int maxn = 10000 ;
 5 int main()
 6 {
 7     int n,q,a[maxn] ,k=0;
 8     while(scanf("%d%d",&n,&q)==2 && n &&q){
 9         for(int i=0;i<n;i++) scanf("%d",&a[i])    ;
10         printf("CASE# %d:\n",++k)    ;
11         sort(a,a+n);
12         while(q--){
13             int x;
14             scanf("%d",&x) ;
15             int p = lower_bound(a,a+n,x) - a;
16             if(a[p] == x) printf("%d found at %d\n",x,p+1) ;
17             else printf("%d not found\n",x) ;
18         }
19     }
20     return 0;
21 }

原文地址:https://www.cnblogs.com/secoding/p/9490632.html

时间: 2024-10-09 09:46:59

大理石在哪儿 (Where is the Marble?,UVa 10474)的相关文章

D - Where is the Marble? (UVA - 10474)

- 题目大意 题目中给出一个n个数的序列和q次查询,每次询问查询值是否在序列内,如果在,输出序列升序排列后的位置(从1开始). - 解题思路 先使用sort()函数进行升序排列,然后枚举出其中与查找的值相同的数,符合条件就输出. - 代码 #include<iostream> #include<algorithm> using namespace std; int num[10000]; int main() { int N, Q,q; int a=1,b=-1; while (c

A - Where is the Marble? UVA - 10474

ACM紫书 第五章 P108 [排序与检索] 题意:找输入的数在排完序之后的位置. 想自己用vector写下,却报错 iterator cannot convert '__gnu_cxx::__normal<int*, std::vector<int> >' to 'int' in assignment ·迭代器的接口几乎相当于普通的指针.让一个迭代器递增只需调用++操作符. 使用*操作符可以得到迭代器引用的数据值.因而迭代器可以被任为是一种智能指针 lower_bound ()返

uva 10474 Where is the Marble?(排序)

uva 10474 Where is the Marble? Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on them. At the beginning, Raju would place the marbles one after another in ascending order of the numbers written on them.

UVA - 10474 - Where is the Marble? (基数排序)

UVA - 10474 Where is the Marble? Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on them. At the beginni

UVA 10474:Where is the Marble?(STL初步)

 Where is the Marble?  Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on them. At the beginning, Raju would place the marbles one after another in ascending order of the numbers written on them. Then Mee

UVA10474 大理石在哪儿 Where is the Marble?

UVA10474 大理石在哪儿 Where is the Marble? 题意翻译 现有N个大理石,每个大理石上写了一个非负整数.首先把各数从小到大排序,然后回 答Q个问题.每个问题问是否有一个大理石写着某个整数x,如果是,还要回答哪个大理石上 写着x.排序后的大理石从左到右编号为1-N. 输入输出样例: //输入 4 1 4个大理石 1个问题 2 2 3 5 1 大理石上写的数字 3 5 1 5 这个5是问题 是否有一个大理石写着5 5 2 1 3 3 3 1 2 3 0 0 //输出 CAS

【UVA - 10474 】Where is the Marble?(排序)

Where is the Marble? Descriptions: Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on them. At the beginning, Raju would place the marbles one after another in ascending order of the numbers written on th

UVA 10474 - Where is the Marble?

Where is the Marble?  Where is the Marble?  Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on them. At the beginning, Raju would place the marbles one after another in ascending order of the numbers writ

大理石在哪里UVa 10474

我自己写的代码 #include<iostream>#include<algorithm>using namespace std;int main(){    int N,a[100],b[100],Q,flag;    int k=1;    while(cin>>N>>Q)    {        for(int i=0;i<N;i++)        {            cin>>a[i];        }        fo