zoukankan      html  css  js  c++  java
  • 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
    ");  
            if(a==0 && b==0 && c!=0)  
                printf("0
    ");  
            else if(a==0 && b!=0)  
                printf("1
    ");  
            else if(a!=0 && (b*b-4*a*c)>0)  
                printf("2
    ");  
            else if(a!=0 && (b*b-4*a*c)==0)  
                printf("1
    ");  
            else if(a!=0 && (b*b-4*a*c)<0)  
                printf("0
    ");  
        }  
        return 0;  
    }
  • 相关阅读:
    slenium截屏
    效率提升
    R语言网页爬虫
    高性能计算
    数据操作
    数据库操作
    面向对象编程
    元编程
    R 的内部机制
    数据处理
  • 原文地址:https://www.cnblogs.com/cmmdc/p/6802006.html
Copyright © 2011-2022 走看看