fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class PlaneGame {
  5. public:
  6.  
  7. int f(vector<int>& x, vector<int>& y)
  8. {
  9. int n = x.size();
  10. double pi = 4.0*atan(1.0);
  11. vector<int> xx(n), yy(n);
  12.  
  13. int b = 0;
  14. for (int i = 0; i < n; i++)
  15. {
  16. double ang;
  17. if (x[i] == 0)
  18. ang = pi/2.0;
  19. else
  20. ang = atan(y[i]/x[i]);
  21. ang = 2*pi-ang;
  22. for (int j = 0; j < n; j++)
  23. {
  24. xx[j] = x[j]*cos(ang)-y[j]*sin(ang);
  25. yy[j] = y[j]*cos(ang)+x[j]*sin(ang);
  26. }
  27. int t = 0;
  28. for (int j = 0; j < n; j++)
  29. {
  30. if (abs(xx[j]) <= 1.0e-8 || abs(yy[j]) <= 1.0e-8)
  31. t++;
  32. }
  33. b = max(b, t);
  34. }
  35.  
  36. return b;
  37.  
  38. }
  39.  
  40. int bestShot(vector <int> x, vector <int> y)
  41. {
  42. int n = x.size();
  43. int m = 0;
  44. for (int i = 0; i < n; i++)
  45. {
  46. vector<int> xx = x, yy = y;
  47. for (int j = 0; j < n; j++)
  48. {
  49. xx[j] -= x[i];
  50. yy[j] -= y[i];
  51. }
  52. m = max(m, f(xx, yy));
  53. }
  54. return m;
  55. }
  56. };
  57.  
  58. int main()
  59. {
  60. PlaneGame obj;
  61. vector<int> x;
  62. vector<int> y;
  63. x.push_back(1);x.push_back(1);x.push_back(-1);x.push_back(-1);
  64. y.push_back(1);y.push_back(-1);y.push_back(-1);y.push_back(1);
  65. cout << obj.bestShot(x, y) << endl;
  66. return 0;
  67. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
3