1065 A+B and C (64bit) (20 分)【难度: 简单 / 思维 高精度】

这篇博客探讨了三种处理数学计算问题的方法,包括使用高精度库、long double浮点类型以及__int128大整数类型。通过实例展示了如何判断三个数是否满足三角形不等式,并提供了相应的输入输出处理函数。文章强调了在处理大数运算时的注意事项和不同方法的适用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述
https://pintia.cn/problem-sets/994805342720868352/problems/994805406352654336
方法一: 用高精度的板子写一下是可以的,不过因为有正负号,故得分类讨论,实属复杂。
方法二: 直接用long double 来计算

#include<bits/stdc++.h> 
using namespace std;
int main(void)
{
	int t; cin>>t;
	for(int i=1;i<=t;i++)
	{
		long double a,b,c; cin>>a>>b>>c;
		if(a+b>c) printf("Case #%d: true\n",i);
		else printf("Case #%d: false\n",i);
	}
	return 0;
}

方法三: 直接用__int128来计算
因为__int128不能直接的读入,故得自己写一个读入的函数,这里直接用p云大佬的代码。

#include <iostream>
using namespace std;
template <typename T>
inline T read()
{
    T sum = 0, fl = 1;
    int ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        if (ch == '-')
            fl = -1;
    for (; isdigit(ch); ch = getchar())
        sum = sum * 10 + ch - '0';
    return sum * fl;
}
int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        __int128_t a, b, c;
        a = read<__int128_t>(), b = read<__int128_t>(), c = read<__int128_t>();
        if (a + b > c) cout << "Case #" << i << ": true" << endl;
        else cout << "Case #" << i << ": false" << endl;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值