总结
今天的模拟赛挂飞了,数论也是一如既往的难啊!!!
考试
T1
直接暴力枚举每种情况是否满足情况就可以了
代码:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1010;
int n, m, k, v;
int x[N];
int get_cnt(int x)
{
int res = 0;
while (x)
{
if (x & 1) res ++ ;
x >>= 1;
}
return res;
}
signed main()
{
cin >> n >> m >> k;
for (int i = 1; i <= m; i ++ ) cin >> x[i];
cin >> v;
int cnt = 0;
for (int i = 1; i <= m; i ++ )
{
int s = v | x[i];
if (get_cnt(s) >= k)
cnt ++ ;
}
cout << cnt << endl;
return 0;
}T2
给定 , 和 ,可以发现 ,然后直接算就可以了。
代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T; cin >> T;
while (T -- )
{
long long a, b, c; cin >> a >> b >> c;
cout << (a + b + c) / 2 << ' ' << (a + b - c) / 2 << endl;
}
return 0;
}T3
可以直接算,但是太复杂了,所以二分。但是 check 写挂了,只得了 ,我太菜了。
代码:
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m, x, y;
bool check(int mid)
{
int need = (n + m) + (n + m) / (x * y);
int a = n / (x - 1) * x, b = m / (y - 1) * y;
if (n % (x - 1) == 0) a -- ;
if (m % (y - 1) == 0) b -- ;
return max({need, a, b}) <= mid;
}
signed main()
{
cin >> n >> m >> x >> y;
int l = n + m, r = 4e9;
while (l < r)
{
int mid = (l + r) >> 1;
if (check(mid)) r = mid;
else l = mid + 1;
}
cout << r << endl;
return 0;
}T4
一道动态规划,没时间了,打了暴力,但是暴力打挂了,同学说我少考虑了一种特殊情况,只得了 。
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5010, MOD = 1e9 + 7;
int n, k, s, e;
int f[N][N];
signed main()
{
cin >> n >> s >> e >> k;
if (s > e)
{
s = n - s + 1;
e = n - e + 1;
swap(s, e);
}
f[0][s] = 1;
for (int i = 1; i <= k; i ++ )
for (int j = 1; j < e; j ++ )
for (int l = 1; l < e; l ++ )
{
if (abs(l - j) >= abs(l - e) || l == j) continue;
f[i][j] = (f[i][j] + f[i - 1][l]) % MOD;
}
int ans = 0;
for (int i = 1; i <= n; i ++ ) ans = (ans + f[k][i]) % MOD;
cout << ans << endl;
return 0;
}突然发现自己写的代码太唐了,其实只要改一点点就能有 。
代码:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5010, MOD = 1e9 + 7;
int n, k, s, e;
int f[N][N];
signed main()
{
cin >> n >> s >> e >> k;
f[0][s] = 1;
for (int i = 1; i <= k; i ++ )
for (int j = 1; j <= n; j ++ )
for (int l = 1; l <= n; l ++ )
{
if (abs(l - j) >= abs(l - e) || l == j) continue;
f[i][j] = (f[i][j] + f[i - 1][l]) % MOD;
}
int ans = 0;
for (int i = 1; i <= n; i ++ ) ans = (ans + f[k][i]) % MOD;
cout << ans << endl;
return 0;
}专题
T1
直接统计阶乘就可以了。
T2
要求一个数与 互质且与 不互质,那就不断地求最大公因数相除判断即可。
T3
直接暴力枚举就可以了,可以证明不会超时。
剩下的就没时间不会做了