1312
- (A题)
测网速
#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;
}
- (B题)
把 (a_i) 从大到小排序即可,必然满足 (j - i ot= a_j - a_i) 因为 (j - i) 是正数,而 (a_j - a_i) 是负数
#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;
}
- C题
没调出来,我 sb了
出现 (k^0,k^1,k^2...k^i) 时可以考虑 (k) 进制 (重要)
那么就把所有的 (a_i) 转换成 (k) 进制,在相同位上出现基数的和如果超过 (1) 那么就不行,注意:(k) 进制全部的元素大小是 (0sim k - 1)
#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
*/
- (D题)
考虑构造题目要求:
从 (1sim m) 个 数中取 (n - 1) 个不同的数出来,那么默认从小到大排序就是 (m_1,m_2,m_3...m_{n-1})
从 (m) 个数中任取 (n -1) 个数是 (C_{m}^{n - 1})
保持 (n - 1) 数中最大值 (m_{n - 1}) 不动,剩下的 (n - 2) 个数在最大值的左边满足上升的条件,任取一个在 (n - 2) 中的数作为相等的数放在右边,有 (n - 2) 种不同的选法,那么剩下的 (n - 3) 个数自由选择放在左边或者右边后可以自动拍个序,自然就满足了条件,对于某一个数放在左边或者右边有两种选法,那么就是 (2^{n - 3})
所以 (C_{m}^{n - 1} imes (n - 2) imes2^{n - 3})
#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;
}
- (E题)待补 (DP)