fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <random>
  4.  
  5. std::vector<std::pair<int, int>> Distance(const std::vector<std::pair<int, int>>& Tower, std::pair<int, int>& Ghost){
  6. std::vector<std::pair<int, int>> ret;
  7. int T = 0;
  8. for (std::size_t i = 0; i < Tower.size(); i++){
  9. T = std::abs(Ghost.first - Tower[i].first)+std::abs(Ghost.second-Tower[i].second);
  10. if (ret.size() == 0){
  11. ret.push_back(std::make_pair(static_cast<int>(i), T));
  12. continue;
  13. }
  14. if (T == ret[0].second){
  15. ret.push_back(std::make_pair(static_cast<int>(i), T));
  16. continue;
  17. }
  18. if (T<ret[0].second){
  19. ret.clear();
  20. ret.push_back(std::make_pair(static_cast<int>(i), T));
  21. continue;
  22. }
  23. }
  24.  
  25. return ret;
  26. }
  27.  
  28. bool Show(char FB[8][8]){
  29. for (int i = 0; i < 8; i++){
  30. for (int j = 0; j < 8; j++){
  31. if (FB[i][j] == 0) std::cout << '+';
  32. else std::cout << FB[i][j];
  33. }
  34. std::cout << std::endl;
  35. }
  36.  
  37. return true;
  38. }
  39.  
  40. bool MakeHoge(const std::vector<std::pair<int, int>>& Tower, std::pair<int, int> Ghost){
  41. char FB[8][8] = { 0, };
  42. for (std::size_t i = 0; i < Tower.size(); i++){
  43. FB[Tower[i].second][Tower[i].first] = 'A' + i;
  44. }
  45. FB[Ghost.second][Ghost.first] = '@';
  46.  
  47. Show(FB);
  48.  
  49. auto Res = Distance(Tower, Ghost);
  50.  
  51. std::cout << "out:";
  52. for (auto& o : Res)std::cout << static_cast<char>('A' + o.first) << '@' << o.second << ' ';
  53. std::cout << std::endl;
  54. std::cout << std::endl;
  55.  
  56. return true;
  57. }
  58. int main(){
  59. std::vector<std::pair<int, int>> vec{ { 2, 2 }, { 5, 2 }, { 2, 5 }, { 5, 5 } };
  60. std::pair<int, int> Ghost{ 3, 3 };
  61.  
  62. std::random_device rd;
  63. std::mt19937 mt(rd());
  64. std::uniform_int_distribution<> uid(0, 7);
  65.  
  66.  
  67. MakeHoge(vec, Ghost);
  68.  
  69. for (int i = 0; i < 8; i++)MakeHoge({ { uid(mt), uid(mt) }, { uid(mt), uid(mt) }, { uid(mt), uid(mt) }, { uid(mt), uid(mt) } }, std::make_pair(uid(mt), uid(mt)));
  70.  
  71. return 0;
  72.  
  73. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
++++++++
++++++++
++A++B++
+++@++++
++++++++
++C++D++
++++++++
++++++++
out:A@2 

++++++++
+@++++++
++++++++
++++++++
+++++A++
DC+++++B
++++++++
++++++++
out:C@4 

++++++++
++++++++
D+++++++
+++++++C
++++++++
+++++@++
A+++++++
++B+++++
out:C@4 

++++++++
++++++A+
++++++++
+++C++++
++++++++
++B+++@+
+++D++++
++++++++
out:A@4 B@4 D@4 

++++++++
+++B++++
++C+++++
++++++++
A+++++++
+D+@++++
++++++++
++++++++
out:D@2 

B+++++++
++++++++
+C++++++
+D++++@+
++++++++
+++++++A
++++++++
++++++++
out:A@3 

++++++++
B+++++A+
++++++++
++++++++
++++++++
++++C+++
++++++@+
D+++++++
out:C@3 

++++++++
++++A+++
++++++++
++++++++
+++++++B
C+++++++
+++++++@
D+++++++
out:B@2 

++++++++
D+++++++
++++++++
+++++++A
++@+++++
++++C+++
++++++++
+++B++++
out:C@3