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