回复 10楼 voidx
对 l 是要 + 1,因为插入了一张鬼。[ 本帖最后由 lz1091914999 于 2011-8-6 22:24 编辑 ]
My life is brilliant
#include <stdio.h> #define add(y, n, L) ((y) + (n) > (L) ? ((y) + (n)) - (L) : (y) + (n)) #define sub(x, m, L) ((x) - (m) < (1) ? ((x) - (m)) + (L) : (x) - (m)) int main(void) { int x, y, m, n, L, t, kx, ky; scanf("%d%d%d%d%d", &x, &y, &m, &n, &L); if(x == y || !x || !y) return 0; for(t = 0, kx = x, ky = y; kx != ky ; t++) { kx = sub(kx, m, L + 1); ky = add(ky, n, L + 1); } printf("%d %d\n", t, kx); // printf("%d %d\n", t, ky); return 0; }
#include <stdio.h> int main(void) { int x, y, m, n, L, t, kx, ky; scanf("%d%d%d%d%d", &x, &y, &m, &n, &L); if(x == y || x < 1 || y < 1 || x > L + 1 || y > L + 1) return 0; for(t = 0, kx = x, ky = y; kx != ky ; t++) { kx = kx - m < 1 ? kx - m + (L + 1) : kx - m; ky = (ky + n) % (L + 1); printf("%d %d\n", kx, ky); } printf("%d %d\n", t, kx); // printf("%d %d\n", t, ky); return 0; }
#include <stdio.h> int main(int argc, char* argv[]) { int x, y, m, n, l; int a, b, k, t; while (scanf("%d %d %d %d %d", &x, &y, &m, &n, &l) == 5) { l++; m = l - m; a = x - y; b = m - n; if (b < 0) { a = -a; b = -b; } if (b == 0) { printf("Impossible\n"); continue; } for (k = (a > 0 ? 1 : 0), t = (k * l - a) % b; t != 0 && k <= b; k++, t = (t + l % b) % b); // 这个循环什么情况下会死循环? if (t == 0) { t = (k * l - a) / b; printf("%d %d\n", t, (t * m + x) % l); } else { printf("Impossible\n"); } } return 0; }
#include <stdio.h> int main(int argc, char* argv[]) { int _x, _y, x, y, m, n, l, t; scanf("%d %d %d %d %d", &_x, &_y, &m, &n, &l); l++; m = l - m; x = (_x + m) % l; y = (_y + n) % l; for (t = 1; x != y && (x != _x || y != _y); t++) { x = (x + m) % l; y = (y + n) % l; } if (x == y) { printf("%d %d", t, x); } else { printf("Impossible"); } return 0; }