大理石在哪里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不会超时. 但是由于以前做比赛时也遇到这种题目,没注意看数据范围,然后暴力 ...
随机推荐
- 解决FTP的URL访问不能有中文名称的问题,报java.lang.IllegalArgumentException
最近一个项目要用到FTP做上传下载,我访问ftp的url中有中文名称,结果每次都报如下错: 1 Exception in thread "main" java.lang.Illeg ...
- A Taxonomy of Computer Organizations
COMPUTER OR GANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION
- [skill][gdb] gdb 多线程调试
中文快速入门: http://coolshell.cn/articles/3643.html (关于多线程的部署说的并不太对) 进阶: 多进程相关概念: inferiors 是什么? http://m ...
- 使用 Swift 在 iOS 10 中集成 Siri —— SiriKit 教程
下载 Xcode 8,配置 iOS 10 和 Swift 3 (可选)通过命令行编译 除 非你想使用命令行编译,使用 Swift 3.0 的工具链并不需要对项目做任何改变.如果你想的话,打开 Xcod ...
- UML之类图
类(Class)封装了数据和行为,是具有相同属性.操作.关系的对象集合的总称. 类图(Class Dialog)使用系统中不同类来描述系统的静态结构,类图用来描述不同类和它们之间的关系. 类图由三部分 ...
- MySql连接Visual studio Code First插件
到mySql官网Downloads==> MySQL on Windows==>MySQL for Visual Studio 下载插件安装即可
- Apple Reject
2016年11月10日 上午1:15 发件人 Apple 2. 1 PERFORMANCE: APP COMPLETENESS Thank you for your resubmission. Per ...
- iOS Developer Library地址
1. iOS Developer Library路径:https://developer.apple.com/library/ios/navigation/ 2. 百度搜索:iOS Developer ...
- storm学习
一 storm 相关术语 . Nimbus storm 集群主节点,负责资源分配和任务调度.(相当于namenode) . supervisor storm集群工作节点,接受Nimbu分配任务,管理w ...
- windows2008吃尽内存的解决办法
最近才用上windows2008,之前一直用的是windows2003,发现系统运行一段时间后,内存吃紧,赶紧打开资源查看器,发现当前运行的程序占有内存都很小,后经查资料,原来是被windows200 ...