高雅憨数笔记

#include <cmath>
double ceil (double); //向上取整
double floor (double); //向下取整
//ceil(3.5) == 4,floor(3.5) == 3
//ceil(4) == floor(4) == 4
注意返回值类型为double,需要强制类型转换为整型
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
    set<int> a;
    int arr[10];
    int b;
    for (int i = 0; i < 10; i++)
    {
        a.insert(i);
        arr[i] = i;
    }
    cout << *a.upper_bound(1) << endl;//返回第一个大于1的元素的地址
    cout << *a.lower_bound(1) << endl;//返回第一个大于等于1的元素的地址,加*才能获取值
    cout << upper_bound(arr, arr + 10, 1) - arr << endl;//减去首地址可获得下标
    cout << lower_bound(arr, arr + 10, 15) - arr << endl;//若没有符合条件的元素,返回尾地址(即setx.end(), arr + n),此时已越界
    cout << (a.upper_bound(11) == a.end()) << endl;
	//注意:函数只是找第一个符合条件的值,若要严格寻找大于x的最小值,使用时数组必须为升序!!!
	cout << binary_search(arr, arr + 10, 1) << endl;//二分查找,返回值为bool类型,找到为1,否则为0
    cout << binary_search(arr, arr + 10, 15) << endl;
    //注意:使用时数组必须为升序!!!
    return 0;
    /*
    输出:
    2
    1
    2
    10
    1
    1
    0
    */
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值