Advertisement
999ms

Untitled

Oct 8th, 2021
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.31 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define all(x) begin(x),end(x)
  4.  
  5. using namespace std;
  6. using ll = long long;
  7.  
  8. const bool INTERACTIVE = false;
  9. const bool BINARY = false;
  10. const bool GENERATE = false;
  11.  
  12. namespace binary_io {
  13.     enum {
  14.         BIG_ENDIAN,
  15.         LITTLE_ENDIAN,
  16.         UNDEF
  17.     };
  18.  
  19.     int get_big(const char *buff) {
  20.         int ans = 0;
  21.         for (int i = 0; i < 4; i++) {
  22.             ans = (ans << 8) ^ uint8_t(buff[i]);
  23.         }
  24.         return ans;
  25.     }
  26.  
  27.     int get_little(char *buff) {
  28.         swap(buff[0], buff[3]);
  29.         swap(buff[1], buff[2]);
  30.         int res = get_big(buff);
  31.         swap(buff[0], buff[3]);
  32.         swap(buff[1], buff[2]);
  33.         return res;
  34.     }
  35.  
  36.     pair<int, int> get_int(ifstream &in, int type) {
  37.         char buff[4];
  38.         in.read(buff, 4);
  39.  
  40.         int resultType = type;
  41.         if (type == UNDEF) {
  42.             if (abs(get_big(buff)) < abs(get_little(buff))) {
  43.                 resultType = BIG_ENDIAN;
  44.             } else {
  45.                 resultType = LITTLE_ENDIAN;
  46.             }
  47.         }
  48.         int res = 0;
  49.         if (resultType == BIG_ENDIAN) {
  50.             res = get_big(buff);
  51.         } else {
  52.             res = get_little(buff);
  53.         }
  54.         return {res, resultType};
  55.     }
  56.  
  57.     void print_int(ofstream &out, int val, int type) {
  58.         char buff[4];
  59.         for (int i = 0; i < 4; i++) {
  60.             if (type == BIG_ENDIAN) {
  61.                 buff[3 - i] = char(val & 255);
  62.             } else {
  63.                 buff[i] = char(val & 255);
  64.             }
  65.             val >>= 8;
  66.         }
  67.         out.write(buff, 4);
  68.     }
  69.  
  70.     void generate_output(ofstream &out) {
  71.         int type = BIG_ENDIAN;
  72.         int n = 5;
  73.         vector<int> values = {-1, -2, -3, -4, -5};
  74.         print_int(out, n, type);
  75.         for (int val: values) {
  76.             print_int(out, val, type);
  77.         }
  78.     }
  79. };
  80.  
  81. template<typename InType, typename OutType>
  82. void solve(InType &in, OutType &out) {
  83.     double a, b, c;
  84.     in >> a >> b >> c;
  85.     if (a == 0) {
  86.         out << 1 << endl;
  87.         out << -c / b << endl;
  88.         return;
  89.     }
  90.     double D = b * b - 4 * a * c;
  91.     if (D < -1e-9) {
  92.         out << 0 << endl;
  93.         return;
  94.     }
  95.     double x1 = (-b - sqrt(D)) / (2 * a);
  96.     out << fixed << setprecision(15);
  97.     if (abs(D) < 1e-9) {
  98.         out << 1 << endl;
  99.         out << x1 << endl;
  100.         return;
  101.     }
  102.     double x2 = (-b + sqrt(D)) / (2 * a);
  103.     out << 2 << endl;
  104.     out << x1 << endl;
  105.     out << x2 << endl;
  106. }
  107.  
  108. int main() {
  109.     ios_base::sync_with_stdio(false);
  110.  
  111.     if (INTERACTIVE) {
  112.         solve(cin, cout);
  113.         exit(0);
  114.     }
  115.  
  116.     ifstream in;
  117.     ofstream out;
  118.     if (INTERACTIVE) {
  119.         in.clear();
  120.         out.clear();
  121.     } else if (BINARY) {
  122.         in = ifstream("input.bin", ios::binary);
  123.         out = ofstream("output.bin", ios::binary);
  124.     } else {
  125.         in = ifstream("input.txt");
  126.         out = ofstream("output.txt");
  127.     }
  128.  
  129.     in.tie(nullptr);
  130.     out.tie(nullptr);
  131.     if (BINARY) {
  132.         if (GENERATE) {
  133.             ofstream o("input.bin", ios::binary);
  134.             binary_io::generate_output(o);
  135.             o.close();
  136.         } else {
  137.             solve(in, out);
  138.         }
  139.     } else {
  140.         solve(in, out);
  141.     }
  142.     in.close();
  143.     out.close();
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement