UVa 10474 - Where is the Marble?
来源:互联网 发布:ubuntu eclipse jdk 编辑:程序博客网 时间:2024/05/29 12:15
题目:给你一些数字和一些查询,问排序后,这些查询的数字最早出现的位置。
分析:简单题。排序后,直接二分查找即可。
说明:排序后直接从前向后扫描也可以,不影响整体效率。
#include <algorithm>#include <iostream>#include <cstdlib>#include <cstdio>using namespace std;int D[10001];int bs( int r, int a ){int mid = r/2,l = 0;while ( l < r ) {mid = l+(r-l)/2;if ( D[mid] < a )l = mid+1;else r = mid;}return r;} int main(){int n,m,T = 1,temp,space;while ( ~scanf("%d%d",&n,&m) && m+n ) {for ( int i = 0 ; i < n ; ++ i )scanf("%d",&D[i]);sort( D, D+n );printf("CASE# %d:\n",T ++);for ( int i = 0 ; i < m ; ++ i ) {scanf("%d",&temp);space = bs( n, temp );if ( D[space] == temp )printf("%d found at %d\n",temp,space+1);else printf("%d not found\n",temp);}}return 0;}
0 0
- UVa 10474 Where is the Marble?
- Uva 10474 Where is the Marble?
- uva 10474 Where is the Marble?
- UVA 10474 Where is the Marble?
- UVA 10474 - Where is the Marble
- uva-10474 - Where is the Marble?
- uva 10474 - Where is the Marble?
- UVA 10474 - Where is the Marble?
- UVa 10474 - Where is the Marble?
- UVa 10474 - Where is the Marble
- UVa 10474 - Where is the Marble?
- UVA 10474 Where is the Marble?
- UVA 10474 - Where is the Marble
- UVa - 10474 - Where is the Marble?
- uva 10474 Where is the Marble?
- uva 10474 Where is the Marble?
- uva - 10474 - Where is the Marble?
- uva 10474 - Where is the Marble
- iOS 学习之 Block
- Access数据类型与.net OleDbType枚举类型的对应
- Ubuntu 13.10/12.10/12.04 用户如何升级到 Ubuntu 14.04
- 电饭锅就李坤城
- python教程
- UVa 10474 - Where is the Marble?
- Tomca6和tomcat7的标签规范区别-taglib definition not consisiten with specification
- win7 的 XP Mode 模式
- 看世界杯!用Swift语言实现播放器
- RHEL资源链接
- git 更改服务器地址
- Android之基于小米天气的天气源库
- Android Bundle传递简单数据、对象数据
- 【BASH】自动清理rman备份文件的脚本