fork download
  1. #include<bits/stdc++.h>
  2. #include<fstream>
  3. #define s(x) scanf("%d",&(x))
  4. #define print(x) printf("%d ",x)
  5. #define printnl(x) printf("%d\n",x);
  6. #define fi(i,a,b) for(int i=(a);i<(b);i++)
  7. #define fd(i,a,b) for(int i=(a);i>(b);--i)
  8. #define MOD 1000000009
  9. #define infy 1e11
  10. #define llu long long unsigned
  11. #define ll long long
  12. #define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
  13. /*By using these macros we can traverse every kind of container, not only vector. This will produce const_iterator for const object and normal iterator for non-const object, and you will never get an error here.
  14.  void f(const vector<int>& v) {
  15.   int r = 0;
  16.   tr(v, it) {
  17.   r += (*it)*(*it);
  18.   }
  19.   return r;
  20.  }*/
  21. #define sz(a) int((a).size())
  22. #define all(c) c.begin(), c.end() // sort(X.rbegin(), X.rend()); // Sort array in descending order using with reverse iterators
  23. #define pb push_back //Push_back adds an element to the end of vector, increasing its size by one
  24. #define isEmpty(v) = v.empty(); //using v.size() takes O(n)
  25. using namespace::std;
  26.  
  27. typedef vector <int> vi; //The following operations are defined for iterators: get value of an iterator, int x = *it; , increment and decrement iterators it1++, it2--; , compare iterators by '!=' and by '<' , add an immediate to iterator it += 20; <=> shift 20 elements forward , get the distance between iterators, int n = it2-it1; , Not only can they operate on any container, they may also perform, for example, range checking and profiling of container usage.
  28. //The type of iterator can be constructed by a type of container by appending “::iterator”, “::const_iterator”, “::reverse_iterator” or “::const_reverse_iterator” to it. use '!=' instead of '<', and 'empty()' instead of 'size() != 0' -- for some container types, it’s just very inefficient to determine which of the iterators precedes another.
  29. typedef vector<vi> vvi; //vector< vector<int> > Matrix(N, vector<int>(M, -1));
  30. typedef pair < int, int > ii; //Pairs are compared first-to-second element. If the first elements are not equal, the result will be based on the comparison of the first elements only; the second elements will be compared only if the first ones are equal. The array (or vector) of pairs can easily be sorted by STL internal functions.(convex hull - For example, if you want to sort the array of integer points so that they form a polygon, it’s a good idea to put them to the vector< pair<double, pair<int,int> >, where each element of vector is { polar angle, { x, y } }. One call to the STL sorting function will give you the desired order of points. )
  31. typedef vector < ii > vii;
  32. typedef vector <vii> vvii;
  33.  
  34. /** sets and maps **/
  35. // set and map have the member functions find() and count(), which works in O(log N), while std::find() and std::count() take O(N).
  36. #include <cstdio>
  37.  
  38. int main()
  39. {
  40. vector<pair<ll, ll > > points(100010);
  41. string a, b;
  42. ll t;
  43. //ios_base::sync_with_stdio(0);
  44. //cin.tie(0);
  45. //freopen("in.txt", "r", stdin);
  46.  
  47. cin>>t;
  48. while(t--)
  49. {
  50. ll n, l1, l2, minx = infy, miny = infy, maxx = -infy, maxy = -infy, flag = 0;
  51. cin>>n;
  52.  
  53. fi(i, 0, n){
  54. cin>>points[i].first>>points[i].second;
  55. if(minx > points[i].first)
  56. minx = points[i].first;
  57. if(miny > points[i].second)
  58. miny = points[i].second;
  59. if(maxx < points[i].first)
  60. maxx = points[i].first;
  61. if(maxy < points[i].second)
  62. maxy = points[i].second;
  63. }
  64.  
  65. fi(i, 0, n)
  66. {
  67. if(points[i].first == minx && points[i].second == miny)
  68. { a = "NE" ; l1 = i+1; flag = 1; } //break; }
  69. if(points[i].first == minx && points[i].second == maxy)
  70. { a = "SE" ; l1 = i+1; flag = 1; } //break; }
  71. if(points[i].first == maxx && points[i].second == miny)
  72. { a = "NW" ; l1 = i+1 ; flag = 1; } //break; }
  73. if(points[i].first == maxx && points[i].second == maxy)
  74. { a = "SW" ; l1 = i+1 ; flag = 1; } //break; }
  75. }
  76.  
  77. if(flag)
  78. {
  79. cout<<1<<endl;
  80. // cout<<"*************************"<<' '<<t<<endl;
  81. cout<<l1<<' '<<a<<endl;
  82. // continue;
  83. }
  84. else
  85. {
  86. int tempy = infy, tempx = -infy;
  87. fi(i, 0, n){
  88. if(points[i].first == minx)
  89. if(tempy > points[i].second)
  90. {
  91. tempy = points[i].second;
  92. l1 = i+1;
  93. }
  94. if(points[i].second == miny)
  95. if(tempx < points[i].first)
  96. {
  97. tempx = points[i].first;
  98. l2 = i+1;
  99. }
  100. }
  101. cout<<2<<endl;
  102. // cout<<"*************************"<<' '<<t<<endl;
  103. cout<<l1<<' '<<"NE"<<endl;
  104. cout<<l2<<' '<<"NW"<<endl;
  105. // continue;
  106. }
  107.  
  108. }
  109. return 0;
  110. }
  111.  
  112. /*The resize() function makes vector contain the required number of elements. If you require less elements than vector already contain, the last ones will be deleted. If you ask vector to grow, it will enlarge its size and fill the newly created elements with zeroes.
  113.  
  114. Note that if you use push_back() after resize(), it will add elements AFTER the newly allocated size, but not INTO it
  115.  
  116. vector<int> v(20);
  117.  for(int i = 0; i < 20; i++) {
  118.   v[i] = i+1;
  119.  }
  120.  v.resize(25);
  121.  for(int i = 20; i < 25; i++) {
  122.   v.push_back(i*2); // Writes to elements with indices [25..30), not [20..25) ! <
  123.  }
  124. *************************
  125. clear() - makes vector to contain 0 elements. It does not make elements zeroes -- watch out -- it completely erases the container.
  126. erase(iterator);
  127.  erase(begin iterator, end iterator);
  128. At first case, single element of vector is deleted. At second case, the interval, specified by two iterators, is erased from vector
  129. *************************
  130. int data[5] = { 1, 5, 2, 4, 3 };
  131.  vector<int> X(data, data+5);
  132.  int v1 = *max_element(X.begin(), X.end()); // Returns value of max element in vector
  133.  int i1 = min_element(X.begin(), X.end()) – X.begin; // Returns index of min element in vector
  134.  
  135.  int v2 = *max_element(data, data+5); // Returns value of max element in array
  136.  int i3 = min_element(data, data+5) – data; // Returns index of min element in array
  137. ********************
  138. void f(const vector<int>& v) {
  139.   int r = 0;
  140.   // Traverse the vector using const_iterator
  141.   for(vector<int>::const_iterator it = v.begin(); it != v.end(); it++) {
  142.   r += (*it)*(*it);
  143.   }
  144.   return r;
  145.  }
  146. *********************/
  147.  
Success #stdin #stdout 0s 3468KB
stdin
2
5
0 0
1 0
2 0
0 -1
0 -2
4
5 0
-5 0
0 5
0 -5
stdout
1
5 NE
2
2 NE
4 NW