UVA 10474
题意:给你一组数,再给几个数问是否在一组数中。
题很简单:STL入门。
没用到STL。
#include<iostream>
#include<cstdio>
#include<algorithm> using namespace std;
int a[];
int main()
{
int ncase = ;
//freopen("in.txt","r",stdin);
int n,m;
while(scanf("%d%d",&n,&m) != EOF){
if(n == && m == )
break;
printf("CASE# %d:\n",ncase++);
for(int i = ;i <= n; i++)
scanf("%d",&a[i]);
sort(a+,a+n+);
for(int i = ;i <= m; i++){
int ans;
scanf("%d",&ans);
int flag = false;
int j;
for(j = ;j <= n; j++)
if(a[j] == ans){
flag = true;
break;
}
if(flag)
printf("%d found at %d\n",ans,j);
else
printf("%d not found\n",ans);
}
}
return ;
}
STL。
#include<iostream>
#include<cstdio>
#include<algorithm> using namespace std;
int a[];
int main()
{
int ncase = ;
//freopen("in.txt","r",stdin);
int n,m;
while(scanf("%d%d",&n,&m) != EOF){
if(n == && m == )
break;
printf("CASE# %d:\n",ncase++);
for(int i = ;i <= n; i++)
scanf("%d",&a[i]);
sort(a+,a+n+);
for(int i = ;i <= m; i++){
int ans;
scanf("%d",&ans);
int flag;
// for(j = 1;j <= n; j++)
// if(a[j] == ans){
// flag = true;
// break;
// }
flag = lower_bound(a+,a+n+,ans) - a; //很容易看出怎么操作的
if(a[flag] == ans)
printf("%d found at %d\n",ans,flag);
else
printf("%d not found\n",ans);
}
}
return ;
}
UVA 10474的更多相关文章
- UVA.10474 Where is the Marble ( 排序 二分查找 )
UVA.10474 Where is the Marble ( 排序 二分查找 ) 题意分析 大水题一道.排序好找到第一个目标数字的位置,返回其下标即可.暴力可过,强行写了一发BS,发现错误百出.应了 ...
- 大理石在哪里UVa 10474
我自己写的代码 #include<iostream>#include<algorithm>using namespace std;int main(){ int N,a[ ...
- UVA 10474 大理石在哪 lower_bound
题意:找输入的数在排完序之后的位置. 主要是lower_bound 函数的使用.它的作用是查找大于或者等于x的第一个位置. #include<cstdio> #include<alg ...
- 大理石在哪?(Where is the Marble?,UVa 10474)
参考:ACM紫书 第五章 P108 [排序与检索] 下面的代码中有些 提示性输出,想Ac 需删除提示性输出语句,读者自行修改. #include <cstdio> #include < ...
- 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?--vector
https://vjudge.net/problem/UVA-10474 https://blog.csdn.net/xiyaozhe/article/details/81081344 简单用法 so ...
- UVA 10474 (13.08.04)
Where is the Marble? Raju and Meena love to play with Marbles. They have got a lotof marbles with ...
- 大理石在哪儿 (Where is the Marble?,UVa 10474)
题目描述:算法竞赛入门经典例题5-1 #include <iostream> #include <algorithm> using namespace std; ; int m ...
随机推荐
- 关于C语言的问卷调查(作业三)
1.你对自己的未来有什么规划?做了哪些准备? 答:我对我未来的规划就是希望能够学有所用,将来可以从事有关IT方面的,跟自己的专业对口.为此现在我需要多看一些和这个专业有关的书籍,自学一些知识,多些一些 ...
- Devexpress Winform Gridcontrol 中根据条件单元格的值改变单元格的颜色等属性。
提供一下三种方法 1.使用设计器 点击gridcontrol控件,run designer,format Condtions, add,然后进行各种条件的设置. 2.用代码代替设计器. 实例代码: p ...
- [转] 使用反射机制控制Toast的显示时间
大体上说就是利用toast的内部类TN 来控制show和hide ,这是一个反射机制 怎么控制toast的显示时间呢?这个就是通过tn类的show和hide的方法 http://blog.csdn.n ...
- Python/dotNET Redis服务连接客户端调用SET方法的同时获取Redis服务器返回的内容
在用Python或dotNET redis客户端连接redis服务器的时候,当你调用客户端的SET方法后同时还想得到其返回的字符串,那么需要处理一下. 1. Redis Python redis客户端 ...
- Spark MLlib 之 Basic Statistics
Spark MLlib提供了一些基本的统计学的算法,下面主要说明一下: 1.Summary statistics 对于RDD[Vector]类型,Spark MLlib提供了colStats的统计方法 ...
- SIT_服务器系统整合测试总结
从2012年到2015年我的3年服务器测试,感觉一下子时间就已经飞逝而过,一直希望做个前三年的工作总结,现在用我那笨拙的笔触记录下自己的三年服务器测试生活! ***2012-2013 SE 这一年基本 ...
- string和char*的相互转换
原文地址: 点击打开链接
- 面向对象to1
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- C++ 11 Template ... 与Decltype 测试
#include <iostream> #include "string" using namespace std; template<typename T> ...
- 关于Webstorm的一些配置
一:代码缩略图插件:CodeGlance: 二:皮肤与主题使用的sublime的系列风格. 三:实现内嵌JS代码的高亮显示.https://segmentfault.com/q/10100000024 ...