天天看點

Mahmoud the Thief Gym - 102035B

題目連結:https://codeforces.com/gym/102035/problem/B

思路:

  1. 相差用取餘解決
  2. n*logn(二分,STL等等)

STL思路:用map記錄%m相同值的個數。

二分思路:由題意知,最多操作n-1次,最少操作0次,二分這個區間。如果剩下1種數ans記錄一次,嘗試有沒有更少的操作次數。

STL代碼:

Mahmoud the Thief Gym - 102035B

二分代碼:

  1. 二進制寫法
    Mahmoud the Thief Gym - 102035B
  2. 一般二分
    Mahmoud the Thief Gym - 102035B