Last active
August 29, 2015 14:08
-
-
Save yuan3y/4ddfebeb01bd6a76007a to your computer and use it in GitHub Desktop.
answer to a simple question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*question: https://www.facebook.com/NTUCollegeOfEngineering/photos/a.373330716093099.88586.332131500213021/709453819147452/?type=1 | |
answered by yuan3y | |
*/ | |
#include<iostream> | |
#include<vector> | |
#include<stack> | |
#include<string> | |
#include<vector> | |
using namespace std; | |
int map[7][7] = { | |
{21,21,42,22,11,22,00}, | |
{21,14,31,22,14,43,33}, | |
{14,11,41,22,14,22,24}, | |
{34,51,22,33,14,33,24}, | |
{22,24,23,23,14,22,12}, | |
{34,21,12,21,14,24,63}, | |
{61,34,21,23,14,23,24} | |
}; | |
bool visited[7][7]={}; | |
stack<vector<int> > order; | |
void trace(int i, int j){ | |
visited[i][j]=true; | |
switch (map[i][j]%10){ | |
case 1: j+=map[i][j]/10; break; | |
case 2: i+=map[i][j]/10; break; | |
case 3: j-=map[i][j]/10; break; | |
case 4: i+=map[i][j]/10; break; | |
case 0: break; | |
} | |
if (!visited[i][j]) | |
trace(i,j); | |
} | |
int main(){ | |
for (int i=0;i<7;i++) | |
for (int j=0;j<7;j++) | |
if (!visited[i][j]) { | |
vector<int> tmp (2,0); | |
tmp[0] =i; | |
tmp[1] =j; | |
order.push(tmp); | |
trace(i,j); | |
} | |
cout<<"row: "<<order.top()[0]+1<<", column: "<<order.top()[1]+1<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment