title: Equations 数学 杭电1840

tags: [数学]

题目链接

Problem Description

All the problems in this contest totally bored you. And every time you get bored you like playing with quadratic equations of the form aX2 + bX + c = 0. This time you are very curious to know how many real solutions an equation of this type has.

Input

The first line of input contains an integer number Q, representing the number of equations to follow. Each of the next Q lines contains 3 integer numbers, separated by blanks, a, b and c, defining an equation. The numbers are from the interval [-1000,1000].

Output

For each of the Q equations, in the order given in the input, print one line containing the number of real solutions of that equation. Print “INF” (without quotes) if the equation has an infinite number of real solutions.

Sample Input

3
1 0 0
1 0 -1
0 0 0

Sample Output

1
2
INF

分析:

就是判断一个方程的跟的个数,首先应该明白的一点就是,如果要用(b^2-4ac)的值来判断的前提必须是这是一个一元二次方程(即a!=0),

如果a=0且b!=0,也就意味着这是一个一元一次方程,

如果a=0切b=0,如果c!=的话,是没有解的,c=0的话,是INF。

代码:

#include<stdio.h>
int main()
{
int s,a,b,c;
scanf("%d",&s);
while(s--)
{
scanf("%d%d%d",&a,&b,&c); if(a==0 && b==0 && c==0)
printf("INF\n");
if(a==0 && b==0 && c!=0)
printf("0\n");
else if(a==0 && b!=0)
printf("1\n");
else if(a!=0 && (b*b-4*a*c)>0)
printf("2\n");
else if(a!=0 && (b*b-4*a*c)==0)
printf("1\n");
else if(a!=0 && (b*b-4*a*c)<0)
printf("0\n");
}
return 0;
}

最新文章

  1. Android课程---序列化与反序列化(转)
  2. Spring事务配置的五种方式 -- 越往后需要Spring版本越高
  3. SDUT 3345 数据结构实验之二叉树六:哈夫曼编码
  4. Delphi接口
  5. android code 和js的交互
  6. POJ 2965 The Pilots Brothers&#39; refrigerator 位运算枚举
  7. 【HDOJ】3451 Beat drop
  8. 《Android开发艺术探索》读书笔记 (13) 第13章 综合技术、第14章 JNI和NDK编程、第15章 Android性能优化
  9. python中从文件中读取数据
  10. java web 学习总结之 Servlet/JSP 编码问题
  11. xss框架基础框架实现
  12. [SCOI2008]城堡
  13. 八大排序算法详解(动图演示 思路分析 实例代码java 复杂度分析 适用场景)
  14. Windows + Flask + Apache + wsgi踏坑总结
  15. Centos7 nginx提示错误 Access denied.
  16. java基础-位运算符
  17. [DQN] What is Deep Reinforcement Learning
  18. Java-Runoob-高级教程-实例-数组:13. Java 实例 – 数组交集
  19. SpringBoot读取application.properties文件内容
  20. linux编译安装php apache mysql (已试过)

热门文章

  1. 你了解的UIKit结构?
  2. 关于ArrayList add()方法 中的引用问题
  3. 第三十三篇 Python中关于OOP(面向对象)的常用术语
  4. 第二十篇 sys模块
  5. PAT——乙级1015/甲级1062:德才论
  6. Unity UGUI 图片 轴对称效果 减少资源
  7. Mybatis学习系列(三)动态SQL
  8. 5for Java
  9. Delphi组件开发教程指南目录
  10. Java IO 之 File 的创建、重命名与遍历