UVa - 10474 Where is the Marble?(STL)
来源:互联网 发布:linux内核开发流程 编辑:程序博客网 时间:2024/04/30 23:23
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19833
#include <iostream>#include <algorithm>#define MAX 10005using namespace std;/************************************************************************************************************** 1, 函数lower_bound()在first和last中的前闭后开区间进行二分查找,返回大于或等于val的第一个元素位置。 如果所有元素都小于val,则返回last的位置 2, 举例如下: 一个数组number序列为:4,10,11,30,69,70,96,100.设要插入数字3,9,111.pos为要插入的位置的下标 则 a:pos = lower_bound( number, number + 8, 3) - number,pos = 0. 即number数组的下标为0的位置。 b:pos = lower_bound( number, number + 8, 9) - number, pos = 1, 即number数组的下标为1的位置(即10所在的位置)。 c:pos = lower_bound( number, number + 8, 111) - number, pos = 8, 即number数组的下标为8的位置(但下标上限为7,所以返回最后一个元素的下一个元素)。 3,所以,要记住:函数lower_bound()在first和last中的前闭后开区间进行二分查找,返回大于或等于val的第一个 元素位置。如果所有元素都小于val,则返回last的位置,且last的位置是越界的!!~ 4,返回查找元素的第一个可安插位置,也就是“元素值>=查找值”的第一个元素的位置**************************************************************************************************************/int a[MAX];int main(){ int n,t,kase=0; while(cin>>n>>t) { cout<<"CASE# "<<++kase<<":"<<endl; for(int i = 1;i <= n;i ++) cin>>a[i]; sort(a+1,a+n+1); while(t--) { int ans; cin>>ans; int id=lower_bound(a+1,a+n+1,ans)-a; if(a[id] == ans) cout<<ans<<" found at "<<id<<endl; else cout<<ans<<" not found"<<endl; } } return 0;}
0 0
- UVA 10474 Where is the Marble? (STL)
- UVa - 10474 Where is the Marble?(STL)
- uva 10474 Where is the Marble?(二分STL)
- UVA 10474:Where is the Marble?(STL初步)
- UVA - 10474 Where is the Marble?(STL,水)
- UVA 10474 Where is the Marble? 暴力|STL
- UVA 10474 Where is the Marble? (STL最简单运用)
- UVA 10474 Where is the Marble(stl,sort)
- UVa 10474Where is the Marble STL 模板练习
- 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?
- 信号量的初始值
- linux驱动中的等待队列头
- UVa - 156 Ananagrams(STL)
- 关于Ping和Tracert命令原理详解
- 1-2 Fibonacci sequence
- UVa - 10474 Where is the Marble?(STL)
- Android开发本地及网络Mp3音乐播放器(十五)网络音乐及歌词下载功能实现
- UVa - 10815 Andy's First Dictionary(STL)
- linux的内核定时器
- poj 1692 Crossed Matchings(DP)
- pull解析
- web前端题目集锦
- ipcs 查询进程间通信状态
- PIM SM + IGMP Snooping 适用性测试(二) ttl 问题