NYOJ 477 A+B Problem III(认识fabs函数)



A+B Problem III

时间限制:1000 ms  |  内存限制:65535 KB

难度:1

描述
求A+B是否与C相等。

输入
T组测试数据。

每组数据中有三个实数A,B,C(-10000.0<=A,B<=10000.0,-20000.0<=C<=20000.0)

数据保证小数点后不超过4位。

输出
如果相等则输出Yes

不相等则输出No

样例输入
3
-11.1 +11.1 0
11 -11.25 -0.25
1 2 +4
样例输出
Yes
Yes
No

刚开始想用字符串的方法,发现可以直接写成浮点数,自己把问题复杂了。虽然是超级水题,但也算借助此题认识了一下fabs函数

fabs函数:

头文件:#include<math.h>;

功能:求浮点数的绝对值;

说明:计算|x|,当x不为负时返回x,否则返回-x。

题目代码如下:

#include<stdio.h>
#include<math.h>
int main()
{
	int n;
	float a,b,c;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%f%f%f",&a,&b,&c);
		if(fabs(a+b-c)<0.0001)//此处可以写成(a+b-c>-0.0001&&a+b-c<0.0001),但不能写成a+b-c==0
		   printf("Yes\n");
		else
		   printf("No\n");
	}
	return 0;
} 
时间: 2024-10-10 17:23:21

NYOJ 477 A+B Problem III(认识fabs函数)的相关文章

NYOJ 题目477 A+B Problem III

题目描述: 求A+B是否与C相等. 输入 T组测试数据.每组数据中有三个实数A,B,C(-10000.0<=A,B<=10000.0,-20000.0<=C<=20000.0)数据保证小数点后不超过4位. 输出 如果相等则输出Yes不相等则输出No 样例输入 3 -11.1 +11.1 0 11 -11.25 -0.25 1 2 +4 样例输出 Yes Yes No #include<stdio.h>int main(){ int N; scanf("%d&q

NYOJ 179 LK&#39;s problem (排序模拟)

链接:click here~~ 题意: 描述 LK has a question.Coule you help her? It is the beginning of the day at a bank, and a crowd  of clients is already waiting for the entrance door to  open. Once the bank opens, no more clients arrive, and  tellerCount tellers be

【POJ 2480】Longge&#39;s problem(欧拉函数)

题意 求$ \sum_{i=1}^n gcd(i,n) $ 给定 $n(1\le n\le 2^{32}) $. 链接 分析 用欧拉函数$φ(x)$求1到x-1有几个和x互质的数. gcd(i,n)必定是n的一个约数.若p是n的约数,那么gcd(i,n)==p的有$φ(n/p)$个数,因为要使gcd(i,n)==p,i/p和n/p必须是互质的.那么就是求i/p和n/p互质的i在[1,n]里有几个,就等价于,1/p,2/p,...,n/p里面有几个和n/p互质,即φ(n/p). 求和的话,约数为p

POJ2480:Longge&#39;s problem(欧拉函数的应用)

题目链接:传送门 题目需求: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i, N) 1<=i <=N. 这题就是上一篇博客的变形. 题目解析:首先先求出与N互质的个数,即N的欧拉函数值,之后分解出N的因子来,求解方法如下. 证明: 要求有多少个 i 满足gcd(i, N) = d 如果gcd(i, N) = d,则gcd(i/d, N/d) = 1 由于i <= N,所以 i/d <= N/d,

POJ 2480 Longge&#39;s problem (欧拉函数+乘性函数)

Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7343   Accepted: 2422 Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now

Longge&#39;s problem(欧拉函数应用)

Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now a problem comes: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i, N) 1<=i <=N.

【POJ】2480 Longge&#39;s problem(欧拉函数)

题目 传送门:QWQ 分析 题意就是求∑gcd(i, N) 1<=i <=N.. 显然$ gcd(i,n) = x $时,必然$x|n$. 所以我们枚举一下n的约数,对于每个约数x,显然$ gcd(i/x,n/x)=1$ 所以我们计算一下n/x的欧拉函数就ok了. 联赛前刷水题qwq 代码 // #include <bits/stdc++.h> #include <cstdio> #include <cmath> #include <algorithm

题解报告:poj 2480 Longge&#39;s problem(欧拉函数)

Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now a problem comes: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i, N) 1<=i <=N. 

NYOJ 698 A Coin Problem (斐波那契)

链接:click here 题意: 描述 One day,Jiameier is tidying up the room,and find some coins. Then she throws the coin to play.Suddenly,she thinks of a problem ,that if throw n times coin ,how many situations of no-continuous up of the coin. Hey,Let's solve the