#include <iostream>
using namespace std;
const int MAX_N = 1000;
int inline index(int i, int j) {
return (i-1)*1000 + (j-1);
}
int inline cycle(int x) {
return (x>1000) ? x-1000 : x<1 ? x+1000 : x;
}
int encode(int i, int j) {
return cycle(i)==cycle(j+1) || cycle(i)==cycle(j-1) ? index(cycle(i+2), cycle(j+2)) : index(cycle(i+1), cycle(j+1));
}
int decode(int i, int j) {
return cycle(i)==cycle(j+1) || cycle(i)==cycle(j-1) ? index(cycle(i-2), cycle(j-2)) : index(cycle(i-1), cycle(j-1));
}
void test() {
for (int i=1;i<=MAX_N;++i)
for (int j=1;j<=MAX_N;++j)
if (i != j) {
int res = encode(i,j);
int i1 = (res / 1000) + 1;
int j1 = (res % 1000) + 1;
if (i1 == i || j1 == i || i1 == j1 || i1 == j || j1 == j || i1<1 || j1<1 || i1>1000 || j1>1000) {
cout << "ERROR " << i << " " << j << " -> " << i1 << " " << j1 << endl;
} else {
int res2 = decode(i1, j1);
int i2 = (res2/1000) + 1;
int j2 = (res2%1000) + 1;
if (i != i2 || j != j2) {
cout << "ERROR " << i << " " << j << " -> " << i1 << " " << j1 << " -> " << i2 << " " << j2 << endl;
} else {
// cout << "OK " << i << " " << j << " -> " << i1 << " " << j1 << " -> " << i2 << " " << j2 << endl;
}
}
}
}
int main() {
string mode;
int x,y;
cin >> mode;
cin >> x >> y;
int result = (mode == "Algosia") ? encode(x,y) : decode(x,y);
int x2 = (result / 1000) + 1;
int y2 = (result % 1000) + 1;
cout << x2 << " " << y2;
cout.flush();
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | #include <iostream> using namespace std; const int MAX_N = 1000; int inline index(int i, int j) { return (i-1)*1000 + (j-1); } int inline cycle(int x) { return (x>1000) ? x-1000 : x<1 ? x+1000 : x; } int encode(int i, int j) { return cycle(i)==cycle(j+1) || cycle(i)==cycle(j-1) ? index(cycle(i+2), cycle(j+2)) : index(cycle(i+1), cycle(j+1)); } int decode(int i, int j) { return cycle(i)==cycle(j+1) || cycle(i)==cycle(j-1) ? index(cycle(i-2), cycle(j-2)) : index(cycle(i-1), cycle(j-1)); } void test() { for (int i=1;i<=MAX_N;++i) for (int j=1;j<=MAX_N;++j) if (i != j) { int res = encode(i,j); int i1 = (res / 1000) + 1; int j1 = (res % 1000) + 1; if (i1 == i || j1 == i || i1 == j1 || i1 == j || j1 == j || i1<1 || j1<1 || i1>1000 || j1>1000) { cout << "ERROR " << i << " " << j << " -> " << i1 << " " << j1 << endl; } else { int res2 = decode(i1, j1); int i2 = (res2/1000) + 1; int j2 = (res2%1000) + 1; if (i != i2 || j != j2) { cout << "ERROR " << i << " " << j << " -> " << i1 << " " << j1 << " -> " << i2 << " " << j2 << endl; } else { // cout << "OK " << i << " " << j << " -> " << i1 << " " << j1 << " -> " << i2 << " " << j2 << endl; } } } } int main() { string mode; int x,y; cin >> mode; cin >> x >> y; int result = (mode == "Algosia") ? encode(x,y) : decode(x,y); int x2 = (result / 1000) + 1; int y2 = (result % 1000) + 1; cout << x2 << " " << y2; cout.flush(); return 0; } |
English