Go to diff to previous submission
#define PROJECT 4 #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <limits> typedef unsigned long long ull; using namespace std; #if PROJECT == 1 int main() { int l, a; while (cin >> l >> a) { int pos; char dir; cin >> pos >> dir; } } #elif PROJECT == 2 #elif PROJECT == 3 #elif PROJECT == 4 int main() { int r, s, gr, gs, lr, ls; int grid[105][105]; //inicializovat este! vector< pair<int,int> > moves; moves.push_back(make_pair(1,2)); moves.push_back(make_pair(1,-2)); moves.push_back(make_pair(-1,2)); moves.push_back(make_pair(-1,-2)); moves.push_back(make_pair(2,1)); moves.push_back(make_pair(2,-1)); moves.push_back(make_pair(-2,1)); moves.push_back(make_pair(-2,-1)); queue< pair<int,int> > todo; while(cin >> r >> s >> gr >> gs >> lr >> ls) { for (int i=0; i<103; i++) for (int j=0; j<103; j++) grid[i][j]=-1; pair<int,int> leaf = make_pair(lr,ls); todo.push(make_pair(gr,gs)); grid[gr][gs]=0; while(!todo.empty()){ pair<int,int> current = todo.front(); todo.pop(); for(vector< pair<int,int> >::iterator i = moves.begin(); i!=moves.end();i++) { pair<int,int> next = make_pair(current.first+i->first,current.second+i->second); if(next.first >= 1 && next.first <= r && next.second >= 1 && next.second <= s){ if(grid[next.first][next.second]==-1) { grid[next.first][next.second]=grid[current.first][current.second]+1; if(next==leaf) { cout << grid[next.first][next.second] << endl; } todo.push(next); } } } } if(grid[leaf.first][leaf.second]==-1) cout << "impossible" << endl; //1==1; } } #elif PROJECT == 5 #elif PROJECT == 6 int main() { unsigned long long m, p, l, e ,r, s, n; while (cin >> m >> p >> l >> e >> r >> s >> n) { for (ull i = 0; i < n; i++) { ull m1, p1, l1; m1 = p / s; p1 = l / r; l1 = m * e; m = m1; p = p1; l = l1; } cout << m << endl; } return 0; } #endif
--- c4.s985.cteam098.grasshop.cpp.0.main.cpp +++ c4.s1055.cteam098.grasshop.cpp.0.main.cpp @@ -28,94 +28,59 @@ #elif PROJECT == 4 -struct task { - int x, y; - task(int _x, int _y) : x(_x), y(_y) {} -}; -int grid[100][100]; +int main() { + int r, s, gr, gs, lr, ls; -const int INF = /* numeric_limits<int>::max() - 1;*/ 100000; + int grid[105][105]; //inicializovat este! -int r, c, gr, gc, lr, lc; -void dump() { - for (int i = 0; i < r; i++) { - for (int j = 0; j < c; j++ ) { - cout << '\t' << (grid[i][j]); - } - endl(cout); - } -} + vector< pair<int,int> > moves; + moves.push_back(make_pair(1,2)); + moves.push_back(make_pair(1,-2)); + moves.push_back(make_pair(-1,2)); + moves.push_back(make_pair(-1,-2)); + moves.push_back(make_pair(2,1)); + moves.push_back(make_pair(2,-1)); + moves.push_back(make_pair(-2,1)); + moves.push_back(make_pair(-2,-1)); -int main() { - while (cin >> r >> c >> gr >> gc >> lr >> lc) { - //endl(cout); - //cout << "#############################################################" << endl << endl; - for (int i = 0; i < r; i++ ) { - for (int j = 0; j < c; j++) { - grid[i][j] = INF; - } - } - gr--, gc--, lr--, lc--; - bool flag = false; - grid[gr][gc] = 0; - queue<task> todo; - todo.push(task(gr, gc)); + queue< pair<int,int> > todo; - while (!todo.empty() || flag) { - task current = todo.front(); todo.pop(); - //cout << "************************" << endl; - // dump(); + while(cin >> r >> s >> gr >> gs >> lr >> ls) + { + for (int i=0; i<103; i++) + for (int j=0; j<103; j++) + grid[i][j]=-1; - for (int i = -2; i <= 2; i++) { - if (i == 0 || current.x + i < 0 || current.x + i > c - 1) continue; + pair<int,int> leaf = make_pair(lr,ls); - if (abs(i) == 1) { - for (int j = -2; j <= 2; j += 4) { - if (current.y + j < 0 || current.y + j > r - 1) continue; + todo.push(make_pair(gr,gs)); + grid[gr][gs]=0; - int tx = current.x + i; - int ty = current.y + j; - if (grid[tx][ty] == INF) { - grid[tx][ty] = grid[current.x][current.y] + 1; - todo.push(task(tx, ty)); - if ((lr == tx) & (lc == ty)) - flag == true; - } + while(!todo.empty()){ - } - } else if (abs(i) == 2) { + pair<int,int> current = todo.front(); + todo.pop(); - for (int j = -1; j <= 1; j += 2) { - if (current.y + j < 0 || current.y + j > r - 1) continue; + for(vector< pair<int,int> >::iterator i = moves.begin(); i!=moves.end();i++) + { + pair<int,int> next = make_pair(current.first+i->first,current.second+i->second); - int tx = current.x + i; - int ty = current.y + j; - if (grid[tx][ty] == INF) { - grid[tx][ty] = grid[current.x][current.y] + 1; - todo.push(task(tx, ty)); - if ((lr == tx) & (lc == ty)) - flag == true; + if(next.first >= 1 && next.first <= r && next.second >= 1 && next.second <= s){ + if(grid[next.first][next.second]==-1) { + grid[next.first][next.second]=grid[current.first][current.second]+1; + if(next==leaf) { + cout << grid[next.first][next.second] << endl; } + todo.push(next); } - }else { - //cerr << "dafuq?" << endl; } } + } - - } - - // cout << "&&&&&&&&&&" << endl; - - if (grid[lr][lc] == INF) { - cout << "impossible" << endl; - - } else { - cout << grid[lr][lc] << endl; - } - + if(grid[leaf.first][leaf.second]==-1) cout << "impossible" << endl; + //1==1; } - return 0; + }