2021-08-15

B. Cat Cycle
B.猫周期

time limit per test: 1 second
每次测试的时间限制:1秒

memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节

input: standard input
输入:标准输入

output: standard output
产出:标准产出

Suppose you are living with two cats: A and B. There are n napping spots where both cats usually sleep.
假设你和两只猫住在一起:A和B。这里有两个睡觉的地方。

Your cats like to sleep and also like all these spots, so they change napping spot each hour cyclically:.
你的猫喜欢睡觉,也喜欢这些地方,所以它们每小时都会改变午睡点。

●Cat A changes its napping place in order.n,n- 1,n- 2,…3,2,1,n,n - 1.,… In other words, at the first hour its on the spot n
CAT A按顺序改变其午睡位置。n,n-1,n-2,.3,2,1,n,n-1,.换句话说,在第一小时,它就在现场

and then goes in decreasing order cyclically;,
然后周期性地递减;

●Cat B changes its napping place in order. 1,2,3…,n- 1, n, 1,2… In other words, at the first hour it’s on the spot 1 and then
CAT B按顺序改变它的午睡位置。1,2,3.,n-1,n,1,2.换句话说,在第一个小时,它是在现场1,然后

goes in increasing order cyclically.
逐级递增。

The cat B is much younger, so they have a strict hierarchy: A and B don’t lie together. In other words, if both cats’d like to go in spot x then
The cat B is much younger, so they have a strict hierarchy: A and B don’t lie together. In other words, if both cats’d like to go in spot x then

the A takes this place and B moves to the next place in its order (ifx < n thentox +十1, butifx = n then to 1). Cat B follows his order,
A取这个位置,B按其顺序移动到下一个位置(ifx<nthentox+十1,butifx=n然后到1)。B猫遵循他的命令,

so it won’t return to the skipped spot x after A frees it, but will move to the spotx + 2 and so on.
所以,在A释放后,它不会返回到跳过的点x,而是移动到点+2,以此类推。

Calculate, where cat B will be at hour k?
算一算,在k小时B猫会在哪里?

Input
输入

The first line contains a single integert(1 < t < 10*)- the number of test cases.
第一行包含一个整数(1<t<10*)–测试用例的数量。

The first and only line of each test case contains two integersnandk(2≤n≤109;1 < k≤109)- the number of spots and hour k:
The first and only line of each test case contains two integersnandk(2≤n≤109;1 < k≤109)- the number of spots and hour k:

Output
输出量

For each test case, print one integer - the index of the spot where cat B will sleep at hour k:.
对于每个测试用例,打印一个整数–CAT B将在h k:睡眠的点的索引。

*** B. Moamen and k-subarrays这题翻版***


int main() {
    int T;
   cin>>T;
    while (T--) {
        int n, k;
        cin>>n>>k;
        if (n & 1) {
            cout<<(k - 1 + (k - 1) / (n / 2)) % n + 1<<endl;
        } else {
            cout<<(k - 1) % n + 1<<endl;
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值