problemscpp
A collection of my answers to algorithm problems in c++.
| 函数
acwing::acwing1470 命名空间参考

  1. 水桶传递队列
更多...

struct  status
 

函数

int main (istream &cin, ostream &cout)
 
 TEST (acwing1470, case1)
 

详细描述

  1. 水桶传递队列

函数说明

◆ main()

int acwing::acwing1470::main ( istream &  cin,
ostream &  cout 
)

在文件 acwing.cpp5940 行定义.

5940 {
5941 char farm[10][10] = {};
5942 pair<int, int> b;
5943 pair<int, int> l;
5944 for(int i = 0; i < 10; i++) {
5945 for(int j = 0; j < 10; j++) {
5946 cin >> farm[i][j];
5947 if(farm[i][j] == 'B') {
5948 b = make_pair(i, j);
5949 } else if(farm[i][j] == 'L') {
5950 l = make_pair(i, j);
5951 }
5952 }
5953 }
5954 priority_queue<status> pq;
5955 pq.push(status(0, l, b));
5956 while(!pq.empty()) {
5957 status s = pq.top();
5958 pq.pop();
5959 if(s.current == b) {
5960 cout << s.len - 1;
5961 return 0;
5962 }
5963 pair<int, int> nexts[4] = {make_pair(s.current.first + 1, s.current.second),
5964 make_pair(s.current.first - 1, s.current.second),
5965 make_pair(s.current.first, s.current.second + 1),
5966 make_pair(s.current.first, s.current.second - 1)};
5967 for(const auto next: nexts) {
5968 if(0 <= next.first && next.first < 10 && 0 <= next.second && next.second < 10 && farm[next.first][next.second] != 'R') {
5969 pq.push(status(s.len + 1, next, b));
5970 }
5971 }
5972 }
5973 return 0;
5974 }

引用了 acwing::acwing1470::status::current , 以及 acwing::acwing1470::status::len.

被这些函数引用 TEST().

◆ TEST()

acwing::acwing1470::TEST ( acwing1470  ,
case1   
)

在文件 acwing_test.cpp2800 行定义.

2800 {
2801 istringstream in("..........\n"
2802 "..........\n"
2803 "..........\n"
2804 "..B.......\n"
2805 "..........\n"
2806 ".....R....\n"
2807 "..........\n"
2808 "..........\n"
2809 ".....L....\n"
2810 "..........");
2811 auto out = ostringstream();
2812 main(in, out);
2813 const auto ans = out.str();
2814 ASSERT_EQ("7", ans);
2815 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().