大理石在哪里UVa 10474
我自己写的代码
#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];
}
for(int j=0;j<Q;j++)
{
cin>>b[j];
}
sort(a,a+N);
for(int j=0;j<Q;j++)
{
flag=0;
cout<<"CASE# "<<k++<<endl;
for(int i=0;i<N;i++)
{
if(a[i]==b[j])
{
cout<<b[j]<<" found at "<<i+1<<endl;
flag=1;
break;
}
}
if(flag==0)
{
cout<<b[j]<<" not found"<<endl;
}
}
}
return 0;
}
书上写的代码
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int N,a[100],Q,x;
int k=1;
while(cin>>N>>Q)
{
for(int i=0;i<N;i++)
{
cin>>a[i];
}
sort(a,a+N);
cout<<"CASE# "<<k++<<endl;
while(Q--)
{
cin>>x;
int p=lower_bound(a,a+N,x)-a;//大于等于x的第一个数的下标
if(a[p]==x)
cout<<x<<" found at "<<p+1<<endl;
else
cout<<x<<" not found"<<endl;
}
}
return 0;
}
哎,自己还是菜的不行啊
大理石在哪里UVa 10474的更多相关文章
- UVA.10474 Where is the Marble ( 排序 二分查找 )
UVA.10474 Where is the Marble ( 排序 二分查找 ) 题意分析 大水题一道.排序好找到第一个目标数字的位置,返回其下标即可.暴力可过,强行写了一发BS,发现错误百出.应了 ...
- 大理石在哪儿(Where is the Marble?,Uva 10474)
现有N个大理石,每个大理石上写了一个非负整数.首先把各数从小到大排序,然后回 答Q个问题.每个问题问是否有一个大理石写着某个整数x,如果是,还要回答哪个大理石上 写着x.排序后的大理石从左到右编号为1 ...
- UVA 10474 大理石在哪 lower_bound
题意:找输入的数在排完序之后的位置. 主要是lower_bound 函数的使用.它的作用是查找大于或者等于x的第一个位置. #include<cstdio> #include<alg ...
- 大理石在哪?(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 ...
- 【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 ...
- UVA 10474
题意:给你一组数,再给几个数问是否在一组数中. 题很简单:STL入门. 没用到STL. #include<iostream> #include<cstdio> #include ...
- UVa 10474 Where is the Marble
题意:给出一列数,先排序,再查找学习了sort函数,lower_bound函数sort:可以给任意对象排序(包括自己定义的)(前提是定义好了‘<’运算符)lower_bound:查找大于或者等于 ...
- uva 10474 Where is the Marble? 计数排序
题目给出一系列数字,然后问哪个数字是从小到大排在第几的,重复出现算第一个. 数据范围为10000,不大,完全可以暴力,sort不会超时. 但是由于以前做比赛时也遇到这种题目,没注意看数据范围,然后暴力 ...
随机推荐
- java 反射获取类的属性 类型 名称和值
/** * 获取属性类型(type),属性名(name),属性值(value)的map组成的list * */ private List getFiledsInfo(Object o){ Field[ ...
- css3知识
一.box-sizing 属性 规定两个并排的带边框的框 二.align-items (适用于父类容器上) 设置或检索弹性盒子元素在侧轴(纵轴)方向上的对齐方式. 值: flex-start:弹性盒子 ...
- JMeter学习-038-JMeter Linux 环境配置
1.1.下载 Download URL:http://mirrors.tuna.tsinghua.edu.cn/apache//jmeter/binaries/apache-jmeter-3.0.tg ...
- vuejs里封装的和IOS,Android通信模块
项目需要,在vuejs开发的web项目中与APP进行通信,实现原理和cordova一致.使用WebViewJavascriptBridge. 其实也是通过拦截url scheme,支持ios6往前的系 ...
- [转]ORACLE函数大全
SQL中的单记录函数 1.ASCII返回与指定的字符对应的十进制数;SQL> select ascii('A') A,ascii('a') a,ascii('0') zero,ascii(' ' ...
- 配置sqlserver端口
今天写java连接数据库时,出现错误:通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败.错误:“Connection refused: connect.请验证连接属性,并 ...
- 解决windows下FileZilla server中文乱码问题
最利用cuteftppro FTP做文件夹同步,发现中文的文件夹及文件名都出现了乱码问题, 一开始以为是cuteftppro的问题,谷哥度娘找了一堆的解决方案都没有解决乱码问题,真是头疼啊! 后来终于 ...
- yii框架的增删改查
一.新增 使用model::save()操作进行新增数据 $user= new User; $user->username =$username; $user->password =$pa ...
- aischool 倒计时VIEW封装
@implementation TWPaperTimeCountLabel { NSInteger miaoshu; dispatch_source_t _timer; } -(id)initWith ...
- C# 提供两种切割圆形图片的方式
效果: private void Form1_Load(object sender, EventArgs e) { string file =System.IO.Path.Combine(Enviro ...