Pagini recente » Cod sursa (job #1323805) | Cod sursa (job #1701965) | Cod sursa (job #2344205) | Cod sursa (job #2309154) | Cod sursa (job #2236125)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream in;
ofstream out;
vector<int> rotate_right(vector<int> directions)
{
vector<int> rotated;
for(auto i: directions)
{
if(i % 2 == 0)
{
rotated.push_back(i - 1);
}
else
{
rotated.push_back(i + 1);
}
}
return rotated;
}
vector<int> rotate_left(vector<int> directions)
{
vector<int> rotated;
for(auto i: directions)
{
rotated.push_back(5 - i);
}
return rotated;
}
vector<int> next_degree(vector<int> directions)
{
vector<int> result;
vector<int> rotated_right = rotate_right(directions);
vector<int> rotated_left = rotate_left(directions);
result.insert(result.end(), rotated_right.begin(), rotated_right.end());
result.push_back(1);
result.insert(result.end(), directions.begin(), directions.end());
result.push_back(2);
result.insert(result.end(), directions.begin(), directions.end());
result.push_back(3);
result.insert(result.end(), rotated_left.begin(), rotated_left.end());
return result;
}
int main() {
int k, x, y, steps = 0, tempx = 1, tempy = 1;
vector<int> directions;
directions.push_back(1);
directions.push_back(2);
directions.push_back(3);
in.open("fractal.in");
in >> k >> x >> y;
in.close();
for(int i = 0; i < k - 1; i++)
{
directions = next_degree(directions);
}
for(auto i: directions)
{
if(tempx == x && tempy == y)
break;
switch(i)
{
case 1:
tempy++;
break;
case 2:
tempx++;
break;
case 3:
tempy--;
break;
case 4:
tempx--;
break;
}
steps++;
}
out.open("fractal.out");
out << steps;
out.close();
return 0;
}