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

https://blog.csdn.net/xiyaozhe/article/details/81081344

简单用法

sort(start,end) 默认是升序

实现降序

#include <functional>

int a[10]={5,6,7,8,9,0,1,2,3,4};

vector <int> v(a, a+10);

sort(v.begin(), v.end(),less<int>());//升

sort(v.begin(), v.end(),greater<int>());//降

find(起点, 终点后一位, 要找的数)

distance (地址, 地址) 是返回容器中两个地址之间的距离

vector基本操作

ve.push_back(a);  
作用是在数组后面增加一个元素。括号里填的是ve里装的东西
ve.clear();清空ve里的所有元素。
ve.empty();判断ve是否为空,如果是返回true,否则false
ve.size();返回ve的长度。注意这里返回的类型是unsigned int,如果ve是空的ve.size() - 1就会爆掉。
ve.pop_back() 删除数组里的最后一个元素。

 #include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
#include<queue>
#include<vector>
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
const long long N=1e9+;
#define LL long long int main()
{
int n,m,number,ca=;
vector<int> ma;
while(cin>>n>>m&&n!=&&m!=)
{
for(int i=;i<n;i++)
{
cin>>number;
ma.push_back(number);
}
sort(ma.begin(),ma.end());
cout<<"CASE# "<<++ca<<":"<<endl;
for(int i=;i<m;i++)
{
cin>>number;
vector<int>::iterator it =find(ma.begin(),ma.end(),number);
if(it==ma.end())
cout << number << " not found"<<endl;
else
cout<<number<<" found at "<<distance(ma.begin(),it)+<<endl;
}
ma.clear();
}
return ;
}

UVA 10474 - Where is the Marble?--vector的更多相关文章

  1. UVA.10474 Where is the Marble ( 排序 二分查找 )

    UVA.10474 Where is the Marble ( 排序 二分查找 ) 题意分析 大水题一道.排序好找到第一个目标数字的位置,返回其下标即可.暴力可过,强行写了一发BS,发现错误百出.应了 ...

  2. UVa 10474 Where is the Marble

    题意:给出一列数,先排序,再查找学习了sort函数,lower_bound函数sort:可以给任意对象排序(包括自己定义的)(前提是定义好了‘<’运算符)lower_bound:查找大于或者等于 ...

  3. uva 10474 Where is the Marble? 计数排序

    题目给出一系列数字,然后问哪个数字是从小到大排在第几的,重复出现算第一个. 数据范围为10000,不大,完全可以暴力,sort不会超时. 但是由于以前做比赛时也遇到这种题目,没注意看数据范围,然后暴力 ...

  4. uva 10474 Where is the Marble?(简单题)

    我非常奇怪为什么要把它归类到回溯上,明明就是简单排序,查找就OK了.wa了两次,我还非常不解的怀疑了为什么会 wa,原来是我居然把要找的数字也排序了,当时仅仅是想着能快一点查找.所以就给他排序了,没考 ...

  5. 【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 ...

  6. Where is the Marble UVA - 10474

     Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on th ...

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

    参考:ACM紫书 第五章 P108 [排序与检索] 下面的代码中有些 提示性输出,想Ac 需删除提示性输出语句,读者自行修改. #include <cstdio> #include < ...

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

    题目描述:算法竞赛入门经典例题5-1 #include <iostream> #include <algorithm> using namespace std; ; int m ...

  9. 大理石在哪儿(Where is the Marble?,Uva 10474)

    现有N个大理石,每个大理石上写了一个非负整数.首先把各数从小到大排序,然后回 答Q个问题.每个问题问是否有一个大理石写着某个整数x,如果是,还要回答哪个大理石上 写着x.排序后的大理石从左到右编号为1 ...

随机推荐

  1. 2.4 random 模块

  2. position:sticky

    使用sticky定位可以简洁的实现固定功能 例如,左右布局页面,左侧菜单,右侧内容,内容区域滚动时,不希望菜单区域滚动,而是固定不动 以往要实现这个功能,需要使用fixed定位菜单,菜单脱离文档流,布 ...

  3. pyspider框架学习

    一.crawl()方法学习: 1.url:爬去是的url,可以定义单个,可以定义为url列表. 2.callback:回调函数,指定该url使用哪个方法来解析. 3.age:任务的有效时间. 4.pr ...

  4. Java之函数式接口

    函数式接口 概述:接口中只有一个抽象方法 下面介绍的可能很抽象,理解不了,至少在我看来单独的这几个借口是没有用的,跟最下面说的 Stream流一起用才会有效果 函数式接口,即适用于函数式编程场景的接口 ...

  5. elastalert 配置post告警方式(备忘)

      最近在做把elk告警日志发送到kinesis 流,供后续数据分析处理使用........ 基于尽量不修改elastalert ,把修改工作放到接收端服务的原则.计划把elk的告警数据通过远程api ...

  6. go Test的实现 以及 压力测试

    引用 import "testing" 一些原则 文件名必须是 *_test.go* 结尾的,这样在执行 go test 的时候才会执行到相应的代码 必须 import testi ...

  7. 精通Dubbo——Dubbo支持的协议的详解

    转: 精通Dubbo——Dubbo支持的协议的详解 2017年06月02日 22:26:57 孙_悟_空 阅读数:44500   Dubbo支持dubbo.rmi.hessian.http.webse ...

  8. zkclient中包引用不对,导致NoSuchMethodError

    nidonglin commented on 31 Oct 2014 Exception in thread "main" java.lang.NoSuchMethodError: ...

  9. 常见Web攻击

    一.SQL注入 1. sql注入的危害 非法读取.篡改.删除数据库中的数据 盗取用户的各类敏感信息,获取利益 通过修改数据库来修改网页上的内容 注入木马等 2. 实例 MYSQLDB # 通过在用户名 ...

  10. Encryption and decryption、Steganography、Decryption Tools

    catalogue . 隐写术 . Substitution cipher . Transposition cipher . Bacon's cipher . LSB-Steganography 1. ...