UVA 10474 大理石在哪 lower_bound】的更多相关文章

题意:找输入的数在排完序之后的位置. 主要是lower_bound 函数的使用.它的作用是查找大于或者等于x的第一个位置. #include<cstdio> #include<algorithm> using namespace std; ; int main() { ; && n){ printf("CASE# %d:\n",++kase); ;i < n; i++) scanf("%d",&a[i]); so…
UVA.10474 Where is the Marble ( 排序 二分查找 ) 题意分析 大水题一道.排序好找到第一个目标数字的位置,返回其下标即可.暴力可过,强行写了一发BS,发现错误百出.应了那句话:基础不牢,地动山摇. 记录一下自己BS的常见错误: 1.需要传入的参数是,搜索的区间[l,r]和搜索的目标值t; 2.一般被搜索的对象以全局变量的身份出现,故不需要传参进去; 3.退出循环的条件是l < r 注意这里可没有等号; 4.若t在mid左边或等于mid,要把右坐标r移动到m的位置,…
现有N个大理石,每个大理石上写了一个非负整数.首先把各数从小到大排序,然后回 答Q个问题.每个问题问是否有一个大理石写着某个整数x,如果是,还要回答哪个大理石上 写着x.排序后的大理石从左到右编号为1-N.(在样例中,为了节约篇幅,所有大理石上 的数合并到一行,所有问题也合并到一行.) 样例输入: 4 1 2 3 5 1 5  5 2 1 3 3 3 1 2 3 样例输出: CASE #1: 5 found at 4 CASE #2: 2 not found 3 found at 3 [分析]…
我自己写的代码 #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…
参考:ACM紫书 第五章 P108 [排序与检索] 下面的代码中有些 提示性输出,想Ac 需删除提示性输出语句,读者自行修改. #include <cstdio> #include <algorithm> using namespace std; const int maxn = 10000; int main(void) { int n,q,numarr[maxn],i,x,p,Case=0; while(scanf("%d%d",&n,&q)…
题目描述:算法竞赛入门经典例题5-1 #include <iostream> #include <algorithm> using namespace std; ; int main() { ; && n &&q){ ;i<n;i++) scanf("%d",&a[i]) ; printf("CASE# %d:\n",++k) ; sort(a,a+n); while(q--){ int x; s…
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…
题意:给你一组数,再给几个数问是否在一组数中. 题很简单:STL入门. 没用到STL. #include<iostream> #include<cstdio> #include<algorithm> using namespace std; ]; int main() { ; //freopen("in.txt","r",stdin); int n,m; while(scanf("%d%d",&n,&a…
题意:给出一列数,先排序,再查找学习了sort函数,lower_bound函数sort:可以给任意对象排序(包括自己定义的)(前提是定义好了‘<’运算符)lower_bound:查找大于或者等于x的第一个位置. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ; int a[maxn]; int main() {…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 排序 用lower_bound找就可以了. ->lower_bound,如果里面所有的数字都比x小,那么它的返回值会越界! [错的次数] 在这里输入错的次数 [反思] 在这里输入反思 [代码] #include <bits/stdc++.h> using namespace std; const int N = 1e4; int n, q, a[N + 10]; int main() { // freopen("…