zoukankan      html  css  js  c++  java
  • Equations(数学,水)

    Equations

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
    Total Submission(s): 689    Accepted Submission(s): 315

    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 a*X2 + b*X + 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
     
    Author
    Mugurel Ionut Andreica
     
    Source
     
    Recommend
    lcy
     

    只要注意a为0的情况就ok

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 #include <cstring>
     5 #include <algorithm>
     6 #define LL long long
     7 #define maxi 2147483647
     8 #define maxl 9223372036854775807
     9 #define dg cout << "Here!" << endl;
    10 using namespace std;
    11 
    12 int main()
    13 {
    14     int q, a, b, c, flag;
    15     cin >> q;
    16     while(q--)
    17     {
    18         cin >> a >> b >> c;
    19         if(!a)
    20         {
    21             if(!b)
    22             {
    23                 if(!c) flag = 3;
    24                 else flag = 0;
    25             }
    26             else flag = 1;
    27         }
    28         else
    29         {
    30             a = b * b - 4 * a * c;
    31             if(!a) flag = 1;
    32             else if(a > 0) flag = 2;
    33             else flag = 0;
    34         }
    35         if(!flag) puts("0");
    36         else if(flag == 1) puts("1");
    37         else if(flag == 2) puts("2");
    38         else puts("INF");
    39     }
    40     return 0;
    41 }
  • 相关阅读:
    继续OI
    [WARNING]考前必读?!
    近些日的总结吧
    续上文
    又是一年NOIP然鹅我考的是高数(虽然我没打并且内容与NOIP无关)(手动滑稽)
    轮船问题(DP基础)
    NOIP2016报零记
    字符数组
    HA-0302 退役
    各种模板(part 2)
  • 原文地址:https://www.cnblogs.com/cszlg/p/2910478.html
Copyright © 2011-2022 走看看