fork(1) download
  1. #include <iostream>
  2. #include <utility>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main() {
  7. int t;
  8. cin >> t;
  9. while(t--) {
  10. int n;
  11. cin >> n;
  12. pair<int,int> p[n];
  13. int xmax,xmin,ymax,ymin;
  14. for(int i=0;i<n;i++) {
  15. cin >> p[i].first >> p[i].second;
  16. if(i == 0) {
  17. xmax = p[i].first;
  18. xmin = p[i].first;
  19. ymax = p[i].second;
  20. ymin = p[i].second;
  21. continue;
  22. }
  23. if(p[i].first > xmax) {
  24. xmax = p[i].first;
  25. }
  26. if(p[i].first < xmin) {
  27. xmin = p[i].first;
  28. }
  29. if(p[i].second > ymax) {
  30. ymax = p[i].second;
  31. }
  32. if(p[i].second < ymin) {
  33. ymin = p[i].second;
  34. }
  35. }
  36. vector< pair<int,int> > v1,v2;
  37. vector<int> index;
  38. for(int i=0;i<n;i++) {
  39. if(p[i].first == xmin) {
  40. v1.push_back(p[i]);
  41. index.push_back(i+1);
  42. }
  43. if(p[i].first == xmax) {
  44. v2.push_back(p[i]);
  45. index.push_back(i+1);
  46. }
  47. }
  48. bool check = true;
  49. for(int i=0;i<v1.size();i++) {
  50. if(v1[i].second == ymax) {
  51. cout << 1 << endl;
  52. cout << index[i] << " SE" << endl;
  53. check = false;
  54. break;
  55. } else if(v1[i].second == ymin) {
  56. cout << 1 << endl;
  57. cout << index[i] << " NE" << endl;
  58. check = false;
  59. break;
  60. }
  61. }
  62. if(!check) {
  63. continue;
  64. }
  65. for(int i=0;i<v2.size();i++) {
  66. if(v2[i].second == ymax) {
  67. cout << 1 << endl;
  68. cout << index[v1.size()+i] << " SW" << endl;
  69. check = false;
  70. break;
  71. } else if(v2[i].second == ymin) {
  72. cout << 1 << endl;
  73. cout << index[v1.size()+i] << " NW" << endl;
  74. check = false;
  75. break;
  76. }
  77. }
  78. if(!check) {
  79. continue;
  80. }
  81. pair<int,int> a = v1[0], b = v2[0];
  82. cout << 2 << endl;
  83. if(a.second <= b.second) {
  84. cout << index[0] << " NW" << endl;
  85. cout << index[v1.size()] << " SE" << endl;
  86. } else {
  87. cout << index[0] << " SW" << endl;
  88. cout << index[v1.size()] << " NE" << endl;
  89. }
  90. }
  91. return 0;
  92. }
  93.  
Success #stdin #stdout 0s 3464KB
stdin
2
5
0 0
1 0
2 0
0 -1
0 -2
4
5 0
-5 0
0 5
0 -5
stdout
1
1 SE
2
1 NW
2 SE