Advertisement
leminhkt

75

Aug 30th, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. const short LOVE = 1411;
  6. const int INF = 1 << 30;
  7. typedef long double db;
  8.  
  9.  
  10. void query() {
  11.     db a, b, c; cin >> a >> b >> c;
  12.  
  13.  
  14.     int ans;
  15.     if (a == 0 && b == 0)
  16.         if (c == 0)
  17.             ans = INF;
  18.         else
  19.             ans = 0;
  20.     else {
  21.         vector<db> p;
  22.         set<db> s;
  23.         db delta;
  24.         if (a == 0)
  25.             p = {-c / b};
  26.         else if (delta = b * b - 4 * a * c, delta >= 0)
  27.             p = {(-b - sqrt(delta)) / (2*a), (-b + sqrt(delta)) / (2*a)};
  28.         for (db no : p)
  29.             if (no >= 0)
  30.                 s.insert(sqrt(no)),
  31.                 s.insert(-sqrt(no));
  32.         ans = s.size();
  33.     }
  34.     if (ans == 0)
  35.         cout << "phuong trinh vo nghiem";
  36.     else if (ans == INF)
  37.         cout << "phuong trinh vo so nghiem";
  38.     else
  39.         cout << "phuong trinh co " << ans << " nghiem";
  40. }
  41.  
  42.  
  43. int main() {
  44.     //freopen("Test.INP", "r", stdin);
  45.     //freopen("Test.OUT", "w", stdout);
  46.     cin.tie(NULL)->sync_with_stdio(false);
  47.  
  48.  
  49.     int t; for (t = 1; t--;) query();
  50.  
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement