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 ...
随机推荐
- magento 2 Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.%
Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on h ...
- Git让你从入门到精通,看这一篇就够了
简介 Git 是什么? Git 是一个开源的分布式版本控制系统. 什么是版本控制? 版本控制是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统. 什么是分布式版本控制系统? 介绍分布 ...
- 解决每次从cmd进入sqlplus,都得重新设置pagesize、linesize的问题
https://blog.csdn.net/u012127798/article/details/34146143/ Oracle里的set零零碎碎的,这里整理归纳一下 SQL> set tim ...
- vue 自定义marquee无缝滚动组件
先上效果图: (1) 看起来可能有点卡顿,但是实际上页面上看起来挺顺畅的. (2) 思路就是获取每一个列表的宽度,设置定时器移动列表,当移动的距离达到一个列表的宽度的时候,把这个距离放到数组的最后.这 ...
- Gaussian Process for Regression
python风控评分卡建模和风控常识(博客主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005214003&am ...
- 使用catboost解决ML中高维度不平衡数据集挑战的解决方案
python风控评分卡建模和风控常识(博客主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005214003&am ...
- CVE-2017-7494 Linux Samba named pipe file Open Vul Lead to DLL Execution
catalogue . 漏洞复现 . 漏洞代码原理分析 . 漏洞利用前提 . 临时缓解 && 修复手段 1. 漏洞复现 . SMB登录上去 . 枚举共享目录,得到共享目录/文件列表,匿 ...
- django - 总结 - redis缓存
八.redis 补充- 操作 - 增删改查 对字典,重新设计结构,增删改查. hmset keys hget scan_iter hgetall import redis import j ...
- 轴对称 Navier-Stokes 方程组的一个点态正则性准则
对轴对称 NSE, 我们改进了 [Pan, Xinghong. A regularity condition of 3d axisymmetric Navier-Stokes equations. A ...
- 过滤器实现 (cookie认证)
cookie用来做身份认证,非常好用,只需要设置Authentication和Authorization就行了. 但是 ,如果cookie不能用了,怎么办? 不要紧,我们也可以用过滤器进行身份认证. ...