牛客周赛 Round 69
牛客周赛 Round 69
2024.11.24 rank373
B
long long格式化输入%d wa一发
C
空间反射 几何关系
D
爆搜 读错题意调一个小时 dfs/数位状压 爆搜每个子方案选不选,判断是否冲突,记录最优方案。
E
将一个数组分为3份,每份和相等且至少有一个正数。问方案数。
------------------------独自思考分割线------------------------
-
E是个好题,D靠码力。
E 3点
1.多种思路:思维/快速查询/dp
2.想到对于每个2/3点快速查询前面满足条件的1/3点即可解决。关键在于如何维护合法数量。假设2/3点前缀正数x,则合法的1/3点的前缀1~x-1。以前缀数量建立数轴,树状数组单点加,区间求和。
3.add(0,c)会超时找好几天bug。
------------------------代码分割线------------------------
A
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T = 1;
// cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int a, b;
cin >> a >> b;
cout << b + b - a << endl;
}
B
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T = 1;
// cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int a, b, c;
scanf("%lld,%lld,...,%lld", &a, &b, &c);
cout << c - b - 1 << endl;
}
C
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T = 1;
// cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, h;
cin >> n >> h;
while (n--)
{
int x, y, z;
cin >> x >> y >> z;
int res = 2 * h - z;
int g = __gcd(x, y);
g = __gcd(g, res);
x /= g, y /= g, res /= g;
cout << x << ' ' << y << ' ' << res << endl;
}
}
D
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T = 1;
// cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, m, q;
cin >> n >> m >> q;
vector<string> a(n);
for (auto &v : a)
cin >> v;
vector<vector<string>> b(q, vector<string>(n));
for (auto &vec : b)
{
for (auto &v : vec)
cin >> v;
}
int res = 1e18;
auto dif = [&](vector<string> &a, vector<string> &b)
{
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (a[i][j] == '1' && b[i][j] == a[i][j])
return 0;
return 1;
};
auto add = [&](vector<string> &a, vector<string> &b)
{
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
a[i][j] = a[i][j] == '1' || b[i][j] == '1' ? '1' : '0';
};
auto ok = [&](vector<string> &t)
{
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (t[i][j] == '0')
return 0;
return 1;
};
auto get = [](int n)
{
int res = 0;
while (n)
{
n -= -n & n;
res++;
}
return res;
};
vector<int> ans;
for (int i = 0; i < 1ll << q; i++)
{
auto t = a;
bool f = 1;
for (int j = 0; i >> j; j++)
if (i >> j & 1)
{
if (dif(a, b[j]))
add(t, b[j]);
else
{
f = 0;
break;
}
}
if (!f)
continue;
if (ok(t))
{
int tans = get(i);
if (tans < res)
{
res = tans;
vector<int> t;
for (int o = 0; i >> o; o++)
if (i >> o & 1)
t.push_back(o + 1);
ans = t;
}
}
}
if (res == (int)1e18)
{
cout << -1 << endl;
return;
}
cout << res << endl;
for (auto v : ans)
cout << v << ' ';
cout << endl;
}
E
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T = 1;
// cin >> T;
while (T--)
_();
return 0;
}
// 树状数组 快速求前缀和
// 维护差分数组(区间加) 位置(统计个数) ...
struct Tree
{
int n;
vector<int> tr;
Tree(int n1)
{
n = n1 + 2;
tr.assign(n + 2, 0);
}
void add(int x, int c) // 加点
{
for (int i = x; i <= n; i += i & -i)
tr[i] += c;
}
int ask(int x) // 前缀查询
{
int res = 0;
for (int i = x; i; i -= i & -i)
res += tr[i];
return res;
}
int ask(int l, int r) // 区间查询
{
if (l > r)
return 0ll;
return ask(r) - ask(l - 1);
}
}; // Tree tr(n); tr.add(x,c)
void _()
{
int n;
cin >> n;
vector<int> a(n + 1), pre(n + 1);
Tree tr(n);
int sum = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
sum += a[i];
pre[i] = pre[i - 1] + (a[i] > 0);
}
if (sum % 3)
{
cout << 0 << endl;
return;
}
int x = sum / 3, res = 0;
sum = 0;
for (int i = 1; i <= n; i++)
{
sum += a[i];
if (sum == x)
{
if (pre[i])
tr.add(pre[i], 1);
}
else if (sum == x << 1 && pre[n] - pre[i])
res += tr.ask(pre[i] - 1);
}
cout << res << endl;
}

浙公网安备 33010602011771号