10474 - Where is the Marble?
Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108&page=show_problem&problem=1415
Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on them. At the beginning, Raju would place the marbles one after another in ascending order of the numbers written on them.
Then Meena would ask Raju to find the first marble with a certain number. She would count 1...2...3. Raju gets one point for correct answer, and Meena gets the point if Raju fails. After some fixed number of trials the game ends and the player with maximum
points wins. Today it's your chance to play as Raju. Being the smart kid, you'd be taking the favor of a computer. But don't underestimate Meena, she had written a program to keep track how much time you're taking to give all the answers. So now you have to
write a program, which will help you in your role as Raju.
There can be multiple test cases. Total no of test cases is less than 65. Each test case consists begins with 2 integers:Nthe
number of marbles andQthe number of queries Mina would make. The nextNlines
would contain the numbers written on theNmarbles. These marble numbers will not come in any particular order. FollowingQlines
will haveQqueries. Be assured, none of the input numbers are greater than 10000 and none of them are negative.
Input is terminated by a test case whereN= 0andQ=
0.
For each test case output the serial number of the case.
For each of the queries, print one line of output. The format of this line will depend upon whether or not the query number is written upon any of the marbles. The two different formats are described below:
- `xfound aty', if the first marble with numberxwas
found at positiony. Positions are numbered1, 2,...,N.
- `xnot found', if the marble with numberxis not present.
Look at the output for sample input for details.
4 1
2
3
5
1
5
5 2
1
3
3
3
1
2
3
0 0
CASE# 1:
5 found at 4
CASE# 2:
2 not found
3 found at 3
使用equal_range()可破。
完整代码:
/*0.118s*/
#include<cstdio>
#include<algorithm>
using namespace std;
int num[10005];
pair<int*, int*> bounds;
int main()
{
int n, q, cas = 0, i, qu;
while (scanf("%d%d", &n, &q), n || q)
{
for (i = 0; i < n; ++i)
scanf("%d", &num[i]);
sort(num, num + n);
printf("CASE# %d:\n", ++cas);
while (q--)
{
scanf("%d", &qu);
bounds = equal_range(num, num + n, qu);
if (bounds.first == bounds.second) printf("%d not found\n", qu);
else printf("%d found at %d\n", qu, bounds.first - num + 1);
}
}
return 0;
}
分享到:
相关推荐
UVA 10474
Marble简介
miui-blockota-marble-V14.0.20.0.TMRCNXM-V14.0.23.0.TMRCNXM-d9821173ec-13.0.zip
Marble diagram generator for learning Reactive Extensions(Rx) expressions. Samples provided.
MARBLE个人作品展示响应式模板基于Bootstrap3.3.5制作,自适应分辨率,兼容PC端和移动端,全套模板,包括首页、博客、作品展示、关于、联系等HTML个人模板页面。
acm2007年里面的marble game,一个不错的编程练习机会啊!!!!
在基本噪声纹理的基础上,引入“颜色带”,实现大理石纹理
MARBLE个人作品展示响应式模板基于Bootstrap3.3.5制作,自适应分辨率,兼容PC端和移动端,全套模板,包括首页、博客、作品展示、关于、联系等HTML个人模板页面。
2-90 unity物理平衡球游戏源码Marble Kit v1.02-90 unity物理平衡球游戏源码Marble Kit v1.02-90 unity物理平衡球游戏源码Marble Kit v1.02-90 unity物理平衡球游戏源码Marble Kit v1.02-90 unity物理平衡球游戏源码...
Marble 是大都会艺术博物馆数字部门的设计系统。 Marble 目前只是一个内部资源项目。 组件资源管理器 我们的组件浏览器由Storybook提供支持,位于: :classical_building: metmuseum.github.io/marble :orange_...
经典的数字地球全球基础底图,分辨率5400*2700,构建三维GIS不可或缺的基础数据。
marble_gl2.xml mars_flight_gl2.xml metahexaballs_gl2.xml misty_lake_gl2.xml mobius_balls_gl2.xml monster_gl2.xml neptune_racing_gl2.xml oblivion_gl2.xml ocean_rescue_gl2.xml on_off_spikes_gl2.xml ...
The technique is efficient even for anisotropic, highly scattering media that are expensive to simulate using existing methods. The model combines an exact solution for single scattering with a dipole...
This is basically a fork of the project solitaire-for-android with changes to suit my crazy desires for what I'm looking for in a Solitaire game. I'd like to add my own type of scoring, which is much ...
Marble Marcher是一款视频游戏演示,使用分形物理引擎和完全程序渲染来制作漂亮而独特的游戏玩法
android-marble-maze
此客户端JavaScript应用程序的核心机制是使用JavaScript和React在24小时内构建的。 React组件的渲染过程受到严格控制,并且100%进行了优化,以最大程度地减少重新渲染和协调。 Marble Machine受到启发。 作为自己...
:alarm_clock: Promster-使用Prometheus测量Hapi,express,Marble.js或Fastify服务器的指标 :vertical_traffic_light: Promster是用于使用Express,Hapi,Marble.js或Fastify编写的Node.js服务器的Prometheus导出...
Marble Blast Epic大理石爆炸史诗Unity祖玛风格游戏项目源码C# 支持Unity版本2017.2.2f1及以上 商品描述 祖玛球爆炸是一款优秀的祖玛风格游戏,该游戏有3个不同的世界,每个世界包含10个级别。 内置 Unity 3d 具有...