P4101 [HEOI2014]人人尽说江南好

https://www.luogu.com.cn/problem/P4101

这个题自己做了一波,做的很心烦,最后也没解出来

百度了一下大佬的,

当n <= m时,合并的次数就是n - 1

当n > m时,合并之后的结果是 n / m个m; 剩下一堆时n % m个

这个时候需要的次数时 (n / m) * (m - 1) + 

n % m = 0 不用加了

否则 n % m - 1;

#include <bits/stdc++.h>
using namespace std;
int n,a,b;
int ans;
int main(){
    //freopen("in","r",stdin);
    ios::sync_with_stdio(0);
    cin >> n;
    while(n--){
        cin >> a >> b;
        ans = 0;
        if(a <= b)
            ans = a - 1;
        else {
            if(a % b) ans += (a % b - 1);
            ans += (a / b) * (b - 1);
        }
        if(ans & 1) cout << 0 << endl;
        else cout << 1 << endl;

    }
}
原文地址:https://www.cnblogs.com/xcfxcf/p/12556713.html