UVA 10474 - Where is the Marble?--vector
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的更多相关文章
- UVA.10474 Where is the Marble ( 排序 二分查找 )
UVA.10474 Where is the Marble ( 排序 二分查找 ) 题意分析 大水题一道.排序好找到第一个目标数字的位置,返回其下标即可.暴力可过,强行写了一发BS,发现错误百出.应了 ...
- UVa 10474 Where is the Marble
题意:给出一列数,先排序,再查找学习了sort函数,lower_bound函数sort:可以给任意对象排序(包括自己定义的)(前提是定义好了‘<’运算符)lower_bound:查找大于或者等于 ...
- uva 10474 Where is the Marble? 计数排序
题目给出一系列数字,然后问哪个数字是从小到大排在第几的,重复出现算第一个. 数据范围为10000,不大,完全可以暴力,sort不会超时. 但是由于以前做比赛时也遇到这种题目,没注意看数据范围,然后暴力 ...
- uva 10474 Where is the Marble?(简单题)
我非常奇怪为什么要把它归类到回溯上,明明就是简单排序,查找就OK了.wa了两次,我还非常不解的怀疑了为什么会 wa,原来是我居然把要找的数字也排序了,当时仅仅是想着能快一点查找.所以就给他排序了,没考 ...
- 【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 ...
- 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 ...
- 大理石在哪?(Where is the Marble?,UVa 10474)
参考:ACM紫书 第五章 P108 [排序与检索] 下面的代码中有些 提示性输出,想Ac 需删除提示性输出语句,读者自行修改. #include <cstdio> #include < ...
- 大理石在哪儿 (Where is the Marble?,UVa 10474)
题目描述:算法竞赛入门经典例题5-1 #include <iostream> #include <algorithm> using namespace std; ; int m ...
- 大理石在哪儿(Where is the Marble?,Uva 10474)
现有N个大理石,每个大理石上写了一个非负整数.首先把各数从小到大排序,然后回 答Q个问题.每个问题问是否有一个大理石写着某个整数x,如果是,还要回答哪个大理石上 写着x.排序后的大理石从左到右编号为1 ...
随机推荐
- macOS修改Dock隐藏速度
延迟时间 修改延迟时间改为0,默认为1. defaults write com.apple.dock autohide-delay -int 0; killall Dock 修改为浮点数值,例如0.1 ...
- 学习Git过程中常用命令的总结
复制远程库git clone git@github.com:Hconly/learngit.git在GitHub上,可以任意Fork开源仓库:自己拥有Fork后的仓库的读写权限:可以推送pull re ...
- Flask Web中文教程
Flask Web中文教程:http://docs.jinkan.org/docs/flask/
- docker学习------docker私有仓库的搭建
192.168.138.102:23451.私有仓库的搭建(docker pull registry),拉取最新的镜像 2.查看拉取的仓库镜像(docker images) 3.启用registry镜 ...
- Codeforces 1101G(线性基)
题目链接 题意 将序列尽可能分成多段使得任意$x \geq 1$段内的所有元素的异或和大于$0$问最多多少段 思路 首先,如果所有元素异或和等于$0$答案显然为$-1$,否则构造整个序列的线性基,这个 ...
- 51nod 1016 水仙花数
大水仙花数模板+1…… #include<stdio.h> #include<math.h> #include<queue> #include<vector& ...
- 学习总结javascript和ajax,php,和css
1,javascript 1,js可以获取和修改html的属性和内容: 通过什么获取? window.onload=function{ document.getElementById("xx ...
- 使用fiddler修改支付金额,支付必测
使用fiddler4先把网页拦截,修改服务器返回的参数,并把修改后的数据包发送给服务器,若该页面价格修改成功则是一个重大bug. 以下是操作流程: 一.拦截订单请求 方法一: 1.在下方命令行输入命令 ...
- Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'
Information:Gradle tasks [:app:assembleDebug]Error:Execution failed for task ':app:transformResource ...
- php exit die的区别
exit 输出一个消息并且退出当前脚本 void exit([string $status]) void exit(int $status)中止脚本的执行.尽管调用了exit(),Shutdow函数以 ...