[Codeforces1487B]Cat Cycle

Link: https://codeforces.com/problemset/problem/1487/B
description:
Cat A sleep from \(n\) downto 1 per hour, while cat B sleep from 1 to n per hour in a cycle(...,n-1, n, then 1,2,...). Cat A has a higher hierarchy, so cat B must skip it when cat a is on its forward spot. Where is cat B at hour \(k\)?
solution:
If \(n\) is even , then there is no conflict, else, cat B skips once per \(\lfloor n/2 \rfloor\) hours.
code:

#include<cstdio>
int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		int n, k;
		scanf("%d%d", &n, &k);
		if (n & 1)  printf("%d\n", (k - 1 + (k - 1) / (n / 2)) % n + 1);
		else printf("%d\n", (k - 1) % n + 1);
	}
}
posted @ 2021-02-22 09:48  _dwt  阅读(55)  评论(0)    收藏  举报