測網速c++
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int mod = 1e9 + 7; typedef long long ll; typedef unsigned long long ull; int a[N]; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; if (n % m == 0) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
把 \(a_i\) 從大到小排序便可,必然知足 \(j - i \not= a_j - a_i\) 由於 \(j - i\) 是正數,而 \(a_j - a_i\) 是負數spa
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int mod = 1e9 + 7; typedef long long ll; typedef unsigned long long ull; ll a[N]; int main() { int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); reverse(a + 1, a + n + 1); for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl; } return 0; }
沒調出來,我 sb了code
==出現 \(k^0,k^1,k^2...k^i\) 時能夠考慮 \(k\) 進制== (重要)排序
那麼就把全部的 \(a_i\) 轉換成 \(k\) 進制,在相同位上出現基數的和若是超過 \(1\) 那麼就不行,注意:\(k\) 進制所有的元素大小是 \(0\sim k - 1\)ci
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int mod = 1e9 + 7; typedef long long ll; typedef unsigned long long ull; ll a[N]; vector<ll> v[N]; ll k, n; map<int, int> mp; void solve(ll x, int pos) { while (x) { v[pos].push_back(x % k); x /= k; } } int main() { int t; cin >> t; while (t--) { mp.clear(); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) v[i].clear(); int maxn = 0; for (int i = 1; i <= n; i++) { solve(a[i], i); maxn = max(maxn, (int)v[i].size()); } for (int i = 1; i <= n; i++) { if ((int)v[i].size() <= maxn) { int cnt = maxn - (int)v[i].size(); for (int j = 1; j <= cnt; j++) v[i].push_back(0); reverse(v[i].begin(), v[i].end()); } } int flag = 0; for (int j = 0; j < maxn; j++) { int cnt = 0; for (int i = 1; i <= n; i++) { cnt += v[i][j]; } if (cnt > 1) flag = 1; } if (flag) cout << "NO" << endl; else cout << "YES" << endl; } return 0; } /* 5 2 20 0 33 2 64 20:0001 0100 0:0000 0000 33:0010 0001 2:0000 0010 64:0100 0000 */
考慮構造題目要求:it
從 \(1\sim m\) 個 數中取 \(n - 1\) 個不一樣的數出來,那麼默認從小到大排序就是 \(m_1,m_2,m_3...m_{n-1}\)io
從 \(m\) 個數中任取 \(n -1\) 個數是 \(C_{m}^{n - 1}\)class
保持 \(n - 1\) 數中最大值 \(m_{n - 1}\) 不動,剩下的 \(n - 2\) 個數在最大值的左邊知足上升的條件,任取一個在 \(n - 2\) 中的數做爲相等的數放在右邊,有 \(n - 2\) 種不一樣的選法,那麼剩下的 \(n - 3\) 個數自由選擇放在左邊或者右邊後能夠自動拍個序,天然就知足了條件,對於某一個數放在左邊或者右邊有兩種選法,那麼就是 \(2^{n - 3}\)map
因此 \(C_{m}^{n - 1}\times (n - 2)\times2^{n - 3}\)im
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int p = 998244353; typedef long long ll; typedef unsigned long long ull; ll pow(ll a, ll b, ll m) { ll ans = 1; a %= m; while (b) { if (b & 1) ans = (ans % m) * (a % m) % m; b /= 2; a = (a % m) * (a % m) % m; } ans %= m; return ans; } ll inv(ll x, ll p) //x關於p的逆元,p爲素數 { return pow(x, p - 2, p); } ll C(ll n, ll m, ll p) //組合數C(n, m) % p { if (m > n) return 0; ll up = 1, down = 1; //分子分母; for (int i = n - m + 1; i <= n; i++) up = up * i % p; for (int i = 1; i <= m; i++) down = down * i % p; return up * inv(down, p) % p; } ll Lucas(ll n, ll m, ll p) { if (m == 0) return 1; return C(n % p, m % p, p) * Lucas(n / p, m / p, p) % p; } int main() { ll n,mx; cin >> n >> mx; if(n <= 2) { cout << 0 << endl; return 0; } ll ans = Lucas(mx, n - 1,p); ans = ans * (n - 2) % p; ans = ans * pow(2, n - 3,p) % p; cout << ans % p << endl; return 0; }