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

AcWing 2019. 拖拉机 更多...

class  acwing2019
 
struct  point
 

函数

int bfs (point start, int **field, int max_x, int max_y)
 
 TEST (acwing2019, case1)
 
 TEST (acwing2019, case2)
 

变量

const int N = 1000
 

详细描述

AcWing 2019. 拖拉机

函数说明

◆ bfs()

int acwing::acwing2019::bfs ( point  start,
int **  field,
int  max_x,
int  max_y 
)

在文件 acwing.cpp434 行定义.

434 {
435 auto que = deque<point>();
436 que.push_front(start);
437 while(!que.empty()) {
438 const auto p = que.front();
439 que.pop_front();
440 point nexts[] = {
441 point(p.x + 1, p.y, p.step), point(p.x - 1, p.y, p.step),
442 point(p.x, p.y + 1, p.step), point(p.x, p.y - 1, p.step)};
443 for(auto next: nexts) {
444 if(next.x == 0 && next.y == 0) {
445 return next.step;
446 }
447 if(0 <= next.x && next.x <= max_x + 2 && 0 <= next.y && next.y <= max_y + 2 &&
448 field[next.x][next.y] != 2) {
449 if(field[next.x][next.y] == 0) {
450 que.push_front(next);
451 } else {
452 //field[nexts.first][nexts.second]==1
453 next.step++;
454 que.push_back(next);
455 }
456 field[next.x][next.y] = 2;
457 }
458 }
459 }
460 return start.step;
461 }

引用了 acwing::acwing2019::point::step.

被这些函数引用 acwing::acwing2019::acwing2019::main().

◆ TEST() [1/2]

acwing::acwing2019::TEST ( acwing2019  ,
case1   
)

在文件 acwing_test.cpp322 行定义.

322 {
323 istringstream in("7 6 3\n"
324 "6 2\n"
325 "5 2\n"
326 "4 3\n"
327 "2 1\n"
328 "7 3\n"
329 "5 4\n"
330 "6 4");
331 auto out = ostringstream();
332 acwing2019::main(in, out);
333 const auto ans = out.str();
334 ASSERT_EQ("1", ans);
335 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().

◆ TEST() [2/2]

acwing::acwing2019::TEST ( acwing2019  ,
case2   
)

在文件 acwing_test.cpp337 行定义.

337 {
338 istringstream in("4 2 2\n"
339 "2 1\n"
340 "1 2\n"
341 "2 3\n"
342 "4 2");
343 auto out = ostringstream();
344 acwing2019::main(in, out);
345 const auto ans = out.str();
346 ASSERT_EQ("0", ans);
347 }

引用了 main().

变量说明

◆ N

const int acwing::acwing2019::N = 1000