F Simple Algebra

题目描述

Given function f(x,y)=ax2+bxy+cy2f(x, y) = a x^2 + b xy + c y^2f(x,y)=ax2+bxy+cy2, check if f(x,y)≥0f(x, y) \geq 0f(x,y)≥0 holds for all x,y∈Rx, y \in \mathbb{R}x,y∈R.

输入描述:

The input contains zero or more test cases and is terminated by end-of-file.
Each test case contains three integers a, b, c.

  • −10≤a,b,c≤10-10 \leq a, b, c \leq 10−10≤a,b,c≤10
  • The number of tests cases does not exceed 10410^4104.

输出描述:

For each case, output “Yes” if f(x,y)≥0f(x, y) \geq 0f(x,y)≥0 always holds. Otherwise, output “No”.

输入

1 -2 1
1 -2 0
0 0 0

输出

Yes
No
Yes

分类讨论,分别讨论a大于小于等于0的情况,然后逐个分析,,当然,这题数据范围小,暴力打表也能过。

#include <iostream>
using namespace std;

void yes()
{
	cout << "Yes" << endl;
}

void no()
{
	cout << "No" << endl;
}

int main()
{
	int a, b, c;
	while(cin >> a>> b>> c)
	{
		if(a < 0)
			no();
		else if(a == 0)
		{
			if(b == 0)
			{
				if(c < 0)
					no();
				else
					yes();
			}
			else
				no();
		}
		else
		{
			if(b * b - 4 * a * c <= 0)
				yes();
			else
				no();
		}
	}
	return 0;
}
发布了73 篇原创文章 · 获赞 15 · 访问量 8110

猜你喜欢

转载自blog.csdn.net/ln2037/article/details/102176585