Educational Codeforces Round 104

2021-02-16  本文已影响0人  burningrain

B. Cat Cycle
直接模拟会超时,n为奇数时,每走n/2步相遇一次

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        if(n%2==0){
            if(k%n==0) cout<<n<<endl;
            else cout<<k%n<<endl;
        }
        else{
            int x=n/2;
            if(k>x){
                if(k%x==0){
                    k=k/x-1+k;
                }else
                    k=k/x+k;
            }
            if(k%n==0) cout<<n<<endl;
            else cout<<k%n<<endl;
        }
    }
    return 0;
}
上一篇 下一篇

猜你喜欢

热点阅读