This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "robot.h"
#include<bits/stdc++.h>
using namespace std;
enum state
{
Start, //當在起點,且已經存在1,代表已經回到起點
Extent, //如果存在0時向四周擴展
Back, //如果不存在0時,代表應返回
End, //-2 -2
Clear, //無路可走時,正式clear,返回到1和4;
Clear_extent, //當周圍存在4時,去找2
};
class robot
{
public:
state robot_state;
vector<int> S;
robot(){return;}
robot(vector<int> _S)//init;
{
S = _S;
if(S[2] == -2 && S[3] == -2)
{
robot_state = state::End;
return;
}
for(int i=0;i<5;i++)
{
if(S[i] == 1 || S[i] == 4) // 周圍存在4;
{
for(int j=1;j<5;j++)
{
if(S[j] == 2)
{
robot_state = state::Clear_extent;
return;
}
}
if((S[1] == -2 && S[4] == -2) && (S[2] == 1 || S[3] == 1))
{
robot_state = state::Start;
return;
}
robot_state = state::Clear;
return;
}
}
for(int it = 1;it<5;it++)
{
if(S[it] == 0)
{
robot_state = state::Extent;
return;
}
}
robot_state = state::Back;
return;
}
};
class instruction
{
public:
robot now_robot;
int Z;
char A = 'H';
char find_direction(int num)
{
if(num == 1)return 'W';
if(num == 2)return 'S';
if(num == 3)return 'E';
if(num == 4)return 'N';
}
instruction(robot _now)
{
now_robot = _now;
if(now_robot.robot_state == state::End)
{
Z = 1;
for(int i=1;i<5;i++)
{
if(now_robot.S[i] == 3)A = find_direction(i);
}
}
if(now_robot.robot_state == state::Extent)
{
for(int i=1;i<5;i++)
{
if(now_robot.S[i] == 0)
{
Z = 3;
A = find_direction(i);
}
}
}
if(now_robot.robot_state == state::Back)
{
for(int i=1;i<5;i++)
{
if(now_robot.S[i] == 3)
{
Z = 2;
A = find_direction(i);
}
}
}
if(now_robot.robot_state == state::Clear)
{
//沿著1或4的方向去走;
bool flag = false;
for(int i=1;i<5;i++)
{
if(now_robot.S[i] == 4)
{
flag = true;
A = find_direction(i);
Z = 0;
}
}
if(flag == false)
{
Z = 1;
for(int i=1;i<5;i++)
{
if(now_robot.S[i] == 3)
{
A = find_direction(i);
Z = 1;
}
}
}
}
if(now_robot.robot_state == state::Clear_extent)
{
for(int i=1;i<5;i++)
{
if(now_robot.S[i] == 2)
{
Z = 4;
A = find_direction(i);
}
}
}
if(now_robot.robot_state == state::Start)
{
Z = 1;
A = 'T';
}
return;
}
void work() //除構造函數外,應寫成 void function() / int function()的形式
{
/*if(now_robot.S[0] == 1 && now_robot.S[1] == 3 && now_robot.S[2] == -2 && now_robot.S[3] == 1 && now_robot.S[4] == -1)
{
cout<<now_robot.robot_state<<" "<<Z<<" "<<A<<endl;
}*/
set_instruction(now_robot.S,Z,A);
return;
}
};
void program_pulibot()
{
vector<int> v;
for(int i=-2;i<=4;i++)v.push_back(i);
for(auto it : v)//可以縮進取代多個大括號
for(auto it2 : v)
for(auto it3 : v)
for(auto it4 : v)
for(auto it5 : v)
{
vector<int> temp;
temp = {it,it2,it3,it4,it5};
robot now_robot(temp);
instruction now_instruction(now_robot);
now_instruction.work();
}
//注 s[0]原地,s[1] 西方,s[2]南方,s[3]東方,s[4]北方
}
Compilation message (stderr)
robot.cpp: In member function 'char instruction::find_direction(int)':
robot.cpp:72:5: warning: control reaches end of non-void function [-Wreturn-type]
72 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |