貪食蛇

 avatar
user_6817964
c_cpp
2 years ago
766 B
3
Indexable
Never
#include <stdio.h> // printf
int main()
{
	int n;
	scanf_s("%d", &n);
	int x = 1, y = 1;
	int k = 0;
	for (int i = 1; i * i <= n; i++) {
		k++;
	}
	if (k % 2 == 0) {
		x = k;
		if (n - k * k == 0)
			x = k; // 這要放啥
		else if (n - k * k == 1)
			x++;
		else if (n - k * k <= k + 1) {
			x++;
			y += n - k * k - 1;
		}
		else if (n - k * k < (k + 1) * 2 - 1) {
			x++;
			y += k;
			x -= (n - k * k) - (k + 1);
		}


	}
	else {
		y = k;
		if (n - k * k == 0)
			y = k; // 這要放啥
		else if (n - k * k == 1)
			y++;
		else if (n - k * k <= k + 1) {
			y++;
			x += n - k * k - 1;
		}
		else if (n - k * k < (k + 1) * 2 - 1) {
			y++;
			x += k;
			y -= (n - k * k) - (k + 1);
		}
	}
	printf("%d %d", x, y);

}