游记
总体来说本次比赛除了T3很恶心以外其他的题都很水。
虽然我这个蒟蒻才315(100 100 15 100),但是写题解还是够了的(
我们考场在北京十二中,系统是NOI Linux,里面有完好的装着C++插件的VSCode,可以开自动格式化,可以F5光速运行。环境比去年好多了,去年PJ我连编译器都没用上导致100 0 0 0险些爆零
T1
快速幂。
过程中判断如果res > 1e9 || a > 1e9即超过范围,否则输出答案。
时间复杂度,
100pts Code:
#include <bits/stdc++.h>
using namespace std;
long long a, b, ans = 1;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
freopen("pow.in", "r", stdin);
freopen("pow.out", "w", stdout);
cin >> a >> b;
while (b)
{
if (b & 1)
ans = ans * a;
b >>= 1;
if (b)
a = a * a;
if (ans > 1e9 || a > 1e9)
{
cout << -1;
return 0;
}
}
cout << ans;
return 0;
}T2
二分。
条件是
总共可能的x范围为,此时
很显然,越接近,乘积越大,满足单调性。二分查找合适的,使。
即为解。
时间复杂度,
100pts Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int T;
ll n, e, d, m;
bool flag;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
freopen("decode.in", "r", stdin);
freopen("decode.out", "w", stdout);
cin >> T;
while (T--)
{
flag = false;
cin >> n >> e >> d;
m = n - e * d + 2;
ll l = 0, r = m >> 1;
while (l <= r)
{
ll mid = l + r >> 1, q = m - mid;
if (mid * q == n)
{
flag = true;
cout << mid << ' ' << q << '\n';
break;
}
if (mid * q < n)
l = mid + 1;
else
r = mid - 1;
}
if (!flag)
cout << "NO\n";
}
return 0;
}T3
模拟。
超级大模拟,恶心死我了!!!
思路:先处理和的情况(直接全删,第二行答案对应的+1),然后处理括号,接着处理,最后处理。
时间复杂度:
代码我不放了,就35pts
upd 11-7:突然又想到一种方法,就是先用stack把括号和优先级抹掉,然后再做。我是傻*。
T4
动态规划。
根据数据范围很显然不能把坐标作为动态规划下标。
定义表示第个点之前用次自建点后联通的最大值。
这里注意一个细节,任何一个都可以作为程序的结束状态。
初始化
转移方程:
(差1可以直接转移,因此最后-1)
最后输出即可(没用完的自建点不要浪费,在结束状态后面接就行)
时间复杂度:
100pts Code:
#include <bits/stdc++.h>
using namespace std;
int n, m, f[505][105];
struct node
{
int x, y;
inline const bool operator<(const node &t) const
{
return x == t.x ? y < t.y : x < t.x;
}
} e[505];
inline int dis(int x, int y)
{
return abs(e[x].x - e[y].x) + abs(e[x].y - e[y].y) - 1;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
freopen("point.in", "r", stdin);
freopen("point.out", "w", stdout);
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> e[i].x >> e[i].y;
sort(e + 1, e + 1 + n);
for (int i = 1; i <= n; i++)
f[i][0] = 1;
for (int i = 2; i <= n; i++)
for (int j = 1; j < i; j++)
if (e[i].x >= e[j].x && e[i].y >= e[j].y)
for (int k = dis(i, j); k <= m; k++)
f[i][k] = max(f[i][k], f[j][k - dis(i, j)] + dis(i, j) + 1);
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = 0; j <= m; j++)
ans = max(ans, f[i][j] + m - j);
cout << ans;
return 0;
}