fork download
  1. #include <boost/multiprecision/cpp_bin_float.hpp>
  2. #include <boost/multiprecision/cpp_dec_float.hpp>
  3. #include <iostream>
  4. #include <cstdint>
  5. #include <vector>
  6. #include <cmath>
  7. #include <limits>
  8. #include <ctime>
  9. using namespace boost::multiprecision;
  10. using namespace std;
  11.  
  12. class PointC {
  13. public:
  14. int64_t x, y;
  15. };
  16.  
  17. template<typename T>
  18. bool is_tri(const PointC& A, const PointC& B, const PointC& C) {
  19. T a = hypot(T(B.x-C.x), T(B.y-C.y));
  20. T b = hypot(T(C.x-A.x), T(C.y-A.y));
  21. T c = hypot(T(A.x-B.x), T(A.y-B.y));
  22.  
  23. T en = 1 - numeric_limits<T>::epsilon()*10;
  24. return a < (b+c)*en && b < (c+a)*en && c < (a+b)*en;
  25. }
  26. template<typename T>
  27. void sub(const vector<PointC>& point, const char* msg) {
  28. const size_t N = point.size();
  29. size_t cnt = 0;
  30.  
  31. clock_t start = clock();
  32. for (size_t i = 0; i < N; ++i)
  33. for (size_t j = i+1; j < N; ++j)
  34. for (size_t k = j+1; k < N; ++k)
  35. if (is_tri<T>(point[i], point[j], point[k]))
  36. ++cnt;
  37. clock_t finish = clock();
  38.  
  39. cout << fixed << left << setw(18) << msg << right << " " << setw(6) << cnt << " "
  40. << static_cast<double>(finish - start)/CLOCKS_PER_SEC << " sec" << endl;
  41. }
  42. int main() {
  43. size_t N;
  44. cin >> N;
  45. vector<PointC> point(N);
  46. for (auto& po : point)
  47. cin >> po.x >> po.y;
  48.  
  49. sub<cpp_bin_float_50 >(point, "cpp_bin_float_50" );
  50. sub<cpp_bin_float_100 >(point, "cpp_bin_float_100" );
  51. sub<cpp_bin_float_quad>(point, "cpp_bin_float_quad");
  52.  
  53. sub<cpp_dec_float_50 >(point, "cpp_dec_float_50" );
  54. sub<cpp_dec_float_100 >(point, "cpp_dec_float_100" );
  55.  
  56. sub<float >(point, "float" );
  57. sub<double >(point, "double" );
  58. sub<long double >(point, "long double" );
  59. }
  60.  
Success #stdin #stdout 0.08s 5528KB
stdin
20
224 433
987654321 987654321
2 0
6 4
314159265 358979323
0 0
-123456789 123456789
-1000000000 1000000000
124 233
9 -6
-4 0
9 5
-7 3
333333333 -333333333
-9 -1
7 -10
-1 5
324 633
1000000000 -1000000000
20 0
stdout
cpp_bin_float_50     1124 0.013004 sec
cpp_bin_float_100    1124 0.034793 sec
cpp_bin_float_quad   1124 0.007946 sec
cpp_dec_float_50     1124 0.007224 sec
cpp_dec_float_100    1124 0.013805 sec
float                 519 0.000032 sec
double               1059 0.000053 sec
long double          1117 0.000141 sec