fork(8) download
  1. #include <bits/stdc++.h>
  2. #define loop(i,n) for (int i = 0; i < n; ++i)
  3. using namespace std;
  4.  
  5. using ldbl = long double;
  6. using cp = complex<ldbl>;
  7.  
  8. const ldbl pi = acos(-1), twice_pi = 2*pi, eps = 1e-10;
  9.  
  10. inline istream& operator>>(istream &in, cp &z) {
  11. ldbl x, y; in >> x >> y, z = cp(x,y); return in; }
  12.  
  13. inline ldbl degrees_to_rad(ldbl angle) { return angle*pi/180; }
  14. inline ldbl rad_to_degress(ldbl angle) { return angle*180/pi; }
  15.  
  16. inline ldbl dot_product(const cp &a, const cp &b) { return real(conj(a)*b); }
  17. inline ldbl cross_product(const cp &a, const cp &b) { return imag(conj(a)*b); }
  18.  
  19. namespace std {
  20. bool operator<(const cp &a, const cp &b) {
  21. ldbl d;
  22. if (abs(d = real(a)-real(b)) > eps)
  23. return d < 0;
  24. if (abs(d = imag(a)-imag(b)) > eps)
  25. return d < 0;
  26. return false; } }
  27.  
  28. inline cp polar_to_cartesian(const ldbl rho, const ldbl theta) {
  29. return polar(rho,theta); }
  30. inline void cartesian_to_polar(const cp &a, ldbl &rho, ldbl &theta) {
  31. rho = abs(a), theta = arg(a); }
  32.  
  33. inline cp rotate(const cp &a, const ldbl theta) {
  34. return a*polar_to_cartesian(1,theta); }
  35. inline cp rotate(const cp &a, const cp &origin, const ldbl theta) {
  36. return origin+(a-origin)*polar_to_cartesian(1,theta); }
  37.  
  38. inline ldbl squared_distance(const cp &a, const cp &b) { return norm(a-b); }
  39. inline ldbl Euclidean_distance(const cp &a, const cp &b) { return abs(a-b); }
  40. inline ldbl angle(const cp &a, const cp &b) { return arg(a-b); }
  41. inline cp unit_vector(const cp &a) { return polar_to_cartesian(1,arg(a)); }
  42. inline cp projection(const cp &p, const cp &v) {
  43. const auto u = unit_vector(v);
  44. return dot_product(p,u)*u; }
  45.  
  46. inline ldbl angle_ABC(const cp &a, const cp &b, const cp &c) {
  47. ldbl g = angle(b,a)-angle(b,c);
  48. if (g <= -pi) // return g in semi-closed interval ]-pi,pi]
  49. g += twice_pi;
  50. if (g > pi)
  51. g -= twice_pi;
  52. return g; }
  53.  
  54. inline ldbl triangle_area(const cp &a, const cp &b, const cp &c) {
  55. const ldbl A = abs(b-a), B = abs(c-b), C = abs(a-c), s = (A+B+C)/2;
  56. return sqrt(s*(s-A)*(s-B)*(s-C)); }
  57.  
  58. struct line: pair<cp,cp> {
  59. ldbl slope() const { return tan(angle(first,second)); }
  60. cp to_vector() const { return second-first; }
  61. cp projection_onto(const cp &p) const {
  62. const auto c = p-first, d = to_vector();
  63. return projection(c,d); }
  64. cp projection_across(const cp &p) const {
  65. const auto c = p-first, d = to_vector();
  66. return c-projection(c,d); }
  67. cp reflect_across(const cp &p) const {
  68. static const auto two = cp(2,0);
  69. const auto c = p-first, d = to_vector();
  70. return two*(first+projection(c,d))-p; }
  71. bool parallel(const line &b) const {
  72. const auto c = to_vector(), u = b.first-first, v = b.second-second;
  73. return abs(cross_product(u,c)-cross_product(v,c)) < eps; }
  74. cp intersection(const line &b) const {
  75. const auto c = to_vector(), u = b.first-first, v = b.second-second;
  76. const auto c1 = cross_product(u,c), c2 = cross_product(v,c);
  77. return (c1*b.second-c2*b.first)/(c2-c1); } };
  78.  
  79. int main() {
  80.  
  81. int n; ldbl x; vector<cp> v;
  82.  
  83. cin >> n, v.resize(n);
  84.  
  85. loop(i,n)
  86. cin >> v[i];
  87.  
  88. sort(v.begin(),v.end());
  89.  
  90. loop(i,n)
  91. cout << v[i] << ' '; }
  92.  
Success #stdin #stdout 0s 4260KB
stdin
5
3.2 -1.0
2.1  1.1
1.4  0.5
1.2  2.1
1.8 -0.2


stdout
(1.2,2.1) (1.4,0.5) (1.8,-0.2) (2.1,1.1) (3.2,-1)