三分模板+int128模板

while(l<r)
    {
        ll midl=l+(r-l)/3;
        ll midr=r-(r-l)/3;
        if(check(midl)<=check(midr))
            r=midr-1;
        else l=midl+1;
    }
#include <bits/stdc++.h>
using namespace std;
inline __int128 read()
{
    __int128 x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
 
inline void write(__int128 x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
        write(x/10);
    putchar(x%10+'0');
}
 
int main()
{
    __int128 a = read();
    write(a);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当使用模板进行冒泡排序算法的分文件编写时,可以按照以下方式进行: **main.cpp:** ```cpp #include <iostream> #include "bubble_sort.h" int main() { int arr[] = {64, 34, 25, 12, 22, 11, 90}; int n = sizeof(arr) / sizeof(arr[0]); bubbleSort<int>(arr, n); std::cout << "排序后的数组:\n"; for (int i = 0; i < n; i++) { std::cout << arr[i] << " "; } std::cout << std::endl; return 0; } ``` **bubble_sort.h:** ```cpp #ifndef BUBBLE_SORT_H #define BUBBLE_SORT_H template<typename T> void bubbleSort(T arr[], int n); #endif ``` **bubble_sort.cpp:** ```cpp #include "bubble_sort.h" template<typename T> void bubbleSort(T arr[], int n) { for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { if (arr[j] > arr[j + 1]) { // 交换arr[j]和arr[j+1] T temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } } // 显式实例化模板函数,以便在链接时生成代码 template void bubbleSort<int>(int arr[], int n); ``` 在这个例子中,我们使用模板函数 `bubbleSort`,它可以接受不同类型的数组进行排序。`bubbleSort` 函数的定义和实现在 `bubble_sort.cpp` 文件中,而函数的声明在 `bubble_sort.h` 文件中。 需要注意的是,在 `bubble_sort.cpp` 文件的末尾,我们使用了显式实例化模板函数的方式,以便在链接时生成代码。 编译和运行这个程序与之前相同,确保"main.cpp"、"bubble_sort.h"和"bubble_sort.cpp"这三个文件处于同一个目录下,并使用C++编译器进行编译。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值