Graph Theory Homework HDU - 6343 (水题不水abs,fabs)

题目传送,走起~~~

代码:

#include<cstdio>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 100010;
int w[maxn];
int main()
{
	int T, n;
	int a, b;
	cin >> T;
	while (T--)
	{
		cin >> n;
		for (int i = 1; i <= n; i++)
		{
			cin >> w[i];
		}
		a = w[1];
		b = w[n];
		int c = int(sqrt(abs(a - b)));
		cout << c << endl;
	}
    return 0;
}

主要区分一下abs()与fabs()

abs()在#include<stdio.h>与#include<cstdilb>头文件中,主要对整数取绝对值(int)型

fabs()在#include<cmath>中精度较高对double,float型求取绝对值。

猜你喜欢

转载自blog.csdn.net/fighting_yifeng/article/details/81455681