好使是好使,但不常用
有与作者忘记头文件都是啥了,就……全写吧
#include<iostream>
#include<algorithm>
#include<cstring>
#include<ctype.h>
#include<math.h>
1、用来求π的值:atan
double pi = 4*atan(1);//π=4*atan(1)
printf("%.10f",pi);
2、ceil/floor:用法等同于[a]+1,[b]
double a,b;
printf("%d\n%d",ceil(a),floor(b));
3、在数组里找第一个大于y的数:lower_bound/upper_bound
cin>>n;
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
scanf("%d",&x);
cout<<*lower_bound(a,a+n-1,x)<<endl;//第一个大于等于x的数字
cout<<*upper_bound(a,a+n-1,x)<<endl;//第一个大于x的数字
4、数组区间修改:fill
int a[N];
scanf("%d",&x);
fill(a,a+n,x);//将a数组改成x
int b[N][N];
scanf("%d%d%d%d",&d,&x,&y,&z);
fill(a[d]+x-1,a[d]+y,-1);//将d行,(x,y)区间内的元素改成z
这篇博客介绍了C++中几个常用的数学和算法库函数,包括求π的atan方法,数值处理的ceil和floor,查找数组中特定值的lower_bound和upper_bound,以及填充数组的fill函数。示例代码清晰地展示了这些函数的使用方法。

3526

被折叠的 条评论
为什么被折叠?



