fork download
  1. //{ Driver Code Starts
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. class Matrix {
  6. public:
  7. template <class T>
  8. static void input(vector<vector<T>> &A, int n, int m) {
  9. for (int i = 0; i < n; i++) {
  10. for (int j = 0; j < m; j++) {
  11. scanf("%d ", &A[i][j]);
  12. }
  13. }
  14. }
  15.  
  16. template <class T>
  17. static void print(vector<vector<T>> &A) {
  18. for (int i = 0; i < A.size(); i++) {
  19. for (int j = 0; j < A[i].size(); j++) {
  20. cout << A[i][j] << " ";
  21. }
  22. cout << endl;
  23. }
  24. }
  25. };
  26.  
  27.  
  28. // } Driver Code Ends
  29.  
  30.  
  31. class Solution {
  32. public:
  33. int countTrips(vector<vector<int>> &locations) {
  34. int n = locations.size();
  35. vector<int>slopes;
  36. for(auto location : locations){
  37. for(int i=0;i<2;i++){
  38. int y = location[1];
  39. int x = location[0];
  40. if(x==0 && y==0) {
  41. n--;
  42. continue;
  43. }
  44. if(x != 0){
  45. int m = y/x;
  46. slopes.push_back(m);
  47. }
  48. else slopes.push_back(y);
  49. }
  50. }
  51. for(auto it: slopes) cout<<it<<" ";
  52. unordered_map<int,int>mpp;
  53. for(int i=0;i<slopes.size();i++){
  54. mpp[i]++;
  55. }
  56. int largest = 0;
  57. for(auto &p : mpp){
  58. if(p.second>largest)largest=p.second;
  59. }
  60. return n-largest+1;
  61. }
  62. };
  63.  
  64.  
  65.  
  66. //{ Driver Code Starts.
  67.  
  68. int main() {
  69. int t;
  70. scanf("%d ", &t);
  71. while (t--) {
  72.  
  73. int n;
  74. scanf("%d", &n);
  75.  
  76. vector<vector<int>> locations(n, vector<int>(2));
  77. Matrix::input(locations, n, 2);
  78.  
  79. Solution obj;
  80. int res = obj.countTrips(locations);
  81.  
  82. cout << res << endl;
  83. cout << "~" << endl;
  84. }
  85. }
  86.  
  87. // } Driver Code Ends
Success #stdin #stdout 0.01s 5288KB
stdin
5
0 0
1 2
2 4
-3 6
4 8
stdout
1
~
1
~
1 1 1
~
-2 -2 2 2 0
~
-3
~