LeetCode LCP 3 机器人大冒险
发布日期:2021-05-11 03:46:23 浏览次数:11 分类:博客文章

本文共 3159 字,大约阅读时间需要 10 分钟。

���������������

���������������������������������������������������������������RURUU������������������������������������������������8���8���������������������������������������������R������������U���������������������������������������������num_R == 2���num_U == 3������������������������������������������������������������������������������������������������������������������������������������������������������x������������������������������������������x == min���8 / 2 ,8 / 3���== 2���������������������������������������������������������������������4���2���������������������������������������������������������������U������������R������������������������������������������������������������������������������������������������������������x������y���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������x <= ������x���y <= ������y���������������������������������������������������������������������������������������������������������������������������������������������

���������������

1 class Solution { 2 public: 3     int min(int x, int y){ 4         return x < y ? x : y; 5     } 6     bool judge(string command, int x_num, int y_num, int x, int y){ 7         int temp = min(x/x_num, y/y_num);       //temp��������������������� 8         x = x - x_num*temp;      //x������������R 9         y = y - y_num*temp;      //y������������U10         //���������x���y���������������������������������������������11         if(x == 0 && y == 0) return true;12         else{13             int len_cmd = command.size();14             for(int i = 0; i < len_cmd; i++){15                 if(command[i] == 'U'){16                     y--;17                     if(y < 0) return false;18                 }else{19                     x--;20                     if(x < 0) return false;21                 }22                 if(x == 0 && y == 0) return true;23             }24         }25         return true;26     }27     bool robot(string command, vector
>& obstacles, int x, int y) {28 int len_cmd = command.size();29 int x_1 = 0;30 int y_1 = 0;31 //���������������������������������������32 for(int i = 0; i < len_cmd; i++){33 if(command[i] == 'R'){34 x_1++;35 }else{36 y_1++;37 }38 }39 //���������������������������������������x���y���������������������x���y��������������������������������� ������������return false40 int len_obs = obstacles.size();41 for(int i = 0; i < len_obs; i++){42 if(obstacles[i][0] <= x && obstacles[i][1] <= y){43 //������������return false44 if(judge(command, x_1, y_1, obstacles[i][0], obstacles[i][1]) == true) return false;45 }46 }47 //������������������������������������������������������ ���������������������������������������48 if(judge(command, x_1, y_1, x, y) == true) return true;49 else return false;50 }51 };

 

上一篇:PAT甲级1001水题飘过
下一篇:HDU4815 Little Tiger vs. Deep Monkey——0-1背包

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2025年04月23日 16时50分51秒