比赛链接

A

代码

#include <bits/stdc++.h>
using namespace std;
using ll = long long; bool solve() {
int n;
cin >> n;
int cnt = 0;
for (int i = 1;i <= n;i++) {
int a, b;
cin >> a >> b;
if (a > b) cnt++;
}
cout << cnt << '\n';
return true;
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}

B

代码

#include <bits/stdc++.h>
using namespace std;
using ll = long long; char dt[4][4];
bool solve() {
for (int i = 1;i <= 3;i++)
for (int j = 1;j <= 3;j++)
cin >> dt[i][j]; for (int i = 1;i <= 3;i++) {
if (dt[i][1] == '.') continue;
bool ok = 1;
for (int j = 1;j <= 3;j++) ok &= dt[i][1] == dt[i][j];
if (ok) {
cout << dt[i][1] << '\n';
return true;
}
}
for (int j = 1;j <= 3;j++) {
if (dt[1][j] == '.') continue;
bool ok = 1;
for (int i = 1;i <= 3;i++) ok &= dt[1][j] == dt[i][j];
if (ok) {
cout << dt[1][j] << '\n';
return true;
}
}
if (dt[1][1] != '.') {
bool ok = 1;
for (int i = 1;i <= 3;i++) ok &= dt[1][1] == dt[i][i];
if (ok) {
cout << dt[1][1] << '\n';
return true;
}
}
if (dt[1][3] != '.') {
bool ok = 1;
for (int i = 1;i <= 3;i++) ok &= dt[1][3] == dt[i][3 - i + 1];
if (ok) {
cout << dt[1][3] << '\n';
return true;
}
}
return false;
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << "DRAW" << '\n';
}
return 0;
}

C

代码

#include <bits/stdc++.h>
using namespace std;
using ll = long long; pair<int, ll> res[200007];
bool solve() {
int n, m, h;
cin >> n >> m >> h;
for (int i = 1;i <= n;i++) {
priority_queue<int, vector<int>, greater<int>> pq;
for (int j = 1;j <= m;j++) {
int x;
cin >> x;
pq.push(x);
} int sum = 0;
int point = 0;
ll penalty = 0;
while (pq.size()) {
int t = pq.top();
pq.pop();
if (sum + t > h) break;
sum += t;
point++;
penalty += sum;
}
res[i] = { point,penalty };
} auto tar = res[1];
auto cmp = [&](pair<int, ll> a, pair<int, ll> b) {return a.first == b.first ? a.second<b.second : a.first>b.first;};
sort(res + 1, res + n + 1, cmp);
int id = lower_bound(res + 1, res + n + 1, tar, cmp) - res;
cout << id << '\n';
return true;
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}

D

代码

#include <bits/stdc++.h>
using namespace std;
using ll = long long; int y[200007] = { (int)2e9 };
bool solve() {
int n;
double d, h;
cin >> n >> d >> h;
for (int i = 1;i <= n;i++) cin >> y[i];
sort(y + 1, y + n + 1, greater<int>()); double ans = 0;
for (int i = 1;i <= n;i++) {
double delta = min(h, 0.0 + y[i - 1] - y[i]);
ans += (2 - delta / h) * d * delta / 2;
}
cout << fixed << setprecision(6) << ans << '\n';
return true;
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}

E

题意

给定一个 \(n\) ,问是否存在 \(k \geq 2 ,s \geq 2\) ,使得 \(\displaystyle n = \sum_{i=0}^s k^i\) 。

题解

方法一

知识点:数学,枚举。

实际上,\(\displaystyle k^s < \sum_{i=0}^s k^i < (k+1)^{s}\) ,因此一定有 \(\displaystyle\left\lfloor \sqrt[s]{\sum_{i=0}^s k^i} \right\rfloor = k\) 。

因此,我们枚举 \(s\) ,令 \(k = \left\lfloor \sqrt[s]{n} \right\rfloor\) ,然后验证这一对 \(s,k\) 。若 \(n\) 可行,那么一定有 \(\displaystyle \sum_{i=0}^s k^i = n\) 。

其中开根号用的是 pow ,这个函数精度很差,但是这里是没有问题的,因为上下界都离得很远。

时间复杂度 \(O(60)\)

空间复杂度 \(O(1)\)

方法二

知识点:数学,二分,枚举。

注意到, \(s\) 不会太大,最大只可能 \(60\) ,考虑枚举 \(s\) 。

对于一个 \(s\) ,由于 \(\displaystyle \sum_{i=0}^s k^i\) 是关于 \(k\) 单调的,我们可以二分 \(k\) ,找到使得 \(\displaystyle \sum_{i=0}^s k^i\) 小于等于 \(n\) 的最后一个 \(k\) ,随后验证这个 \(k\) 是否是答案即可。

注意到, \(k\) 也不会超过 \(10^9\) ,这个结论能降低常数。

时间复杂度 \(O(60 \times \log 10^9)\)

空间复杂度 \(O(1)\)

方法三

知识点:数学,二分,枚举。

对于 \(s \geq 3\) 的情况, \(k\) 不会超过 \(10^6\) ,因此可以枚举 \(k \leq 10^6\) ,对每个 \(k\) 预处理出 \(s \in[3,60]\) 的所有答案。

对于 \(s = 2\) 的情况,和方法一一样直接二分即可。

时间复杂度 \(\displaystyle O\left( \left(\sum_{k=2}^{10^6}\log_k 10^{18}\right) \cdot \log \left(\sum_{k=2}^{10^6}\log_k 10^{18}\right) + \log 10^9 \right)\)

空间复杂度 \(\displaystyle O\left(\sum_{k=2}^{10^6}\log_k 10^{18}\right)\)

代码

方法一

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using i128 = __int128_t; i128 qpow(i128 a, ll k) {
i128 ans = 1;
while (k) {
if (k & 1) ans *= a;
k >>= 1;
a *= a;
}
return ans;
} bool solve() {
ll n;
cin >> n;
for (int i = 2, k;(k = pow(n, 1.0 / i)) >= 2;i++) {
i128 res = (1 - qpow(k, i + 1)) / (1 - k);
if (res == n) {
cout << "YES" << '\n';
return true;
}
}
return false;
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << "NO" << '\n';
}
return 0;
}

方法二

#include <bits/stdc++.h>
using namespace std;
using ll = long long; const ll INF = 2e18;
ll calc(int x, int s) {
ll sum = 0;
__int128_t mul = 1;
for (int i = 0;i <= s;i++) {
if (sum + mul > INF) return INF;
sum += mul;
mul *= x;
}
return sum;
} bool solve() {
ll n;
cin >> n;
for (int i = 2;i <= 60;i++) {
int l = 2, r = 1e9;
while (l <= r) {
int mid = l + r >> 1;
if (calc(mid, i) <= n) l = mid + 1;
else r = mid - 1;
}
if (r >= 2 && calc(r, i) == n) {
cout << "YES" << '\n';
return true;
}
}
return false;
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << "NO" << '\n';
}
return 0;
}

方法三

#include <bits/stdc++.h>
using namespace std;
using ll = long long; const ll INF = 1e18;
set<ll> st;
void init() {
for (int i = 2;i <= 1000000;i++) {
ll sum = 1 + i + 1LL * i * i;
while (1 + (__int128_t)sum * i <= INF) {
sum = 1 + sum * i;
st.insert(sum);
}
}
} ll calc(int x) {
return 1 + x + 1LL * x * x;
} bool solve() {
ll n;
cin >> n; if (st.count(n)) {
cout << "YES" << '\n';
return true;
} int l = 2, r = 1e9;
while (l <= r) {
int mid = l + r >> 1;
if (calc(mid) <= n) l = mid + 1;
else r = mid - 1;
}
if (r >= 2 && calc(r) == n) {
cout << "YES" << '\n';
return true;
}
return false;
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
init();
while (t--) {
if (!solve()) cout << "NO" << '\n';
}
return 0;
}

F

题意

房间里有 \(n\) 个物品,每个物品的种类为 \(a_i\) 。这些物品中,有一个是模仿者伪装的。

现在可以进行一场最多 \(5\) 轮的实验去找出它,每一轮按顺序发生如下事件:

  1. 记录当前房间内的所有物品的种类。
  2. 可指出一个物品确定是伪装的,则试验结束。但这个操作只能执行一次,若不确定,则要做下一步操作。
  3. 选出一些物品移出房间(可以不选,但模仿者始终不会被移出房间)并离开房间。随后房间里的物品会被打乱,模仿者也可以转换成别的物品(即使房间里不存在的物品)。
  4. 进入房间,继续下一轮。模仿者可能不转变,但最多保持两轮是同一个类型的物品。

给出操作,找到模仿者。

题解

知识点:枚举。

一开始可以不移出物品,这样若模仿者发生变化,则最多两轮一定有一个类型的物品多了一个。

移出除了多出来物品的类型以外类型的所有物品。

剩下的一定是包括模仿者的同一类型的物品,再最多不超过一轮,一定会出现一个不同类型的物品,就是模仿者。

时间复杂度 \(O(n)\)

空间复杂度 \(O(n)\)

代码

#include <bits/stdc++.h>
using namespace std;
using ll = long long; int n;
int a[207];
int cnt1[10], cnt2[10]; void query(const vector<int> &del) {
cout << "- " << del.size() << " ";
for (auto x : del) cout << x << " ";
cout << endl;
n -= del.size();
for (int i = 1;i <= n;i++) cin >> a[i];
} void answer(int x) {
cout << "! " << x << endl;
} bool solve() {
for (int i = 1;i <= 9;i++) cnt1[i] = cnt2[i] = 0; cin >> n;
for (int i = 1;i <= n;i++) cin >> a[i], cnt1[a[i]]++; query({});
for (int i = 1;i <= n;i++) cnt2[a[i]]++; int type = 0;
for (int i = 1;i <= 9;i++) {
if (cnt1[i] < cnt2[i]) {
type = i;
break;
}
} if (!type) {
for (int i = 1;i <= 9;i++) cnt2[i] = 0;
query({});
for (int i = 1;i <= n;i++) cnt2[a[i]]++;
for (int i = 1;i <= 9;i++) {
if (cnt1[i] < cnt2[i]) {
type = i;
break;
}
}
} vector<int> del;
for (int i = 1;i <= n;i++) if (a[i] != type) del.push_back(i);
query(del); bool ok = 0;
for (int i = 1;i <= n;i++) {
if (a[i] != type) {
answer(i);
ok = 1;
break;
}
} if (!ok) {
query({});
for (int i = 1;i <= n;i++) {
if (a[i] != type) {
answer(i);
ok = 1;
break;
}
}
}
return true;
} int main() {
//std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}

G

题意

有 \(n\) 种症状和 \(m\) 个药品,症状的情况通过一个长为 \(n\) 的 \(01\) 串给出。

每种药品治疗效果是可以使特定的一些症状消失,但副作用是使得特定的症状出现。

每种药有一个疗程 \(d\) ,疗程之内不允许使用其他药。

现在给出初始症状情况,问最少需要多少天才能使得症状全部消失。

题解

知识点:最短路,状压dp,拓扑序dp。

考虑状压,将症状压缩为一个整数。

随后,我们将 \(2^n\) 种症状情况看作点, \(m\) 种药看作边。显然,每个点都可以有 \(m\) 条出边。

假设当前的症状是 \(st\) ,将要使用的药品的效果是 \(e\) ,副作用是 \(se\) ,那么使用后的症状为 (st & ~e) | se ,这样就构建了一条边,权值为疗程时间。

问题就变成,从初始状态到 \(0\) 状态的最短路,直接跑最短路即可。

求最短路的本质就是在最短路图这个DAG上进行拓扑序dp,因此一些dp可以考虑抽象成图的形式跑最短路。

时间复杂度 \(O(m2^n \log (m2^n))\)

空间复杂度 \(O(2^n + m)\)

代码

#include <bits/stdc++.h>
using namespace std;
using ll = long long; int n, m;
int d[1007], e[1007], se[1007]; bool vis[1 << 10 + 1];
int dis[1 << 10 + 1];
struct node {
int v, w;
friend bool operator<(const node &a, const node &b) { return a.w > b.w; }
};
priority_queue<node> pq;
void dijkstra(int st) {
for (int i = 0;i < (1 << n);i++) dis[i] = 1e9, vis[i] = 0;
dis[st] = 0;
pq.push({ st,0 });
while (!pq.empty()) {
int u = pq.top().v;
pq.pop();
if (vis[u]) continue;
vis[u] = 1;
for (int i = 1;i <= m;i++) {
int v = (u & ~e[i]) | se[i];
int w = d[i];
if (dis[v] > dis[u] + w) {
dis[v] = dis[u] + w;
pq.push({ v,dis[v] });
}
}
}
} bool solve() {
cin >> n >> m;
int st = 0;
for (int i = 0;i < n;i++) {
char ch;
cin >> ch;
st |= (ch == '1') << i;
}
for (int i = 1;i <= m;i++) {
cin >> d[i];
e[i] = 0, se[i] = 0;
for (int j = 0;j < n;j++) {
char ch;
cin >> ch;
e[i] |= (ch == '1') << j;
}
for (int j = 0;j < n;j++) {
char ch;
cin >> ch;
se[i] |= (ch == '1') << j;
}
}
dijkstra(st);
cout << (dis[0] >= 1e9 ? -1 : dis[0]) << '\n';
return true;
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}

Codeforces Round #883 (Div. 3) A-G的更多相关文章

  1. Educational Codeforces Round 47 (Div 2) (A~G)

    目录 Codeforces 1009 A.Game Shopping B.Minimum Ternary String C.Annoying Present D.Relatively Prime Gr ...

  2. Educational Codeforces Round 46 (Div 2) (A~G)

    目录 Codeforces 1000 A.Codehorses T-shirts B.Light It Up C.Covered Points Count(差分) D.Yet Another Prob ...

  3. Educational Codeforces Round 45 (Div 2) (A~G)

    目录 Codeforces 990 A.Commentary Boxes B.Micro-World C.Bracket Sequences Concatenation Problem D.Graph ...

  4. Codeforces Round #582 (Div. 3)-G. Path Queries-并查集

    Codeforces Round #582 (Div. 3)-G. Path Queries-并查集 [Problem Description] 给你一棵树,求有多少条简单路径\((u,v)\),满足 ...

  5. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  6. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  7. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

  8. Codeforces Round #383 (Div. 2) 题解【ABCDE】

    Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...

  9. 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram

    题目地址:http://codeforces.com/contest/435/problem/C /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...

  10. Codeforces Round #368 (Div. 2) B. Bakery (模拟)

    Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...

随机推荐

  1. 26-code split

    第一种:多入口 const { resolve } = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin' ...

  2. 记一次 .NET 某外贸ERP 内存暴涨分析

    一:背景 1. 讲故事 上周有位朋友找到我,说他的 API 被多次调用后出现了内存暴涨,让我帮忙看下是怎么回事?看样子是有些担心,但也不是特别担心,那既然找到我,就给他分析一下吧. 二:WinDbg ...

  3. AndroidApp加固与脱壳

    0x01 APP加固 01.为什么要加固 APP加固是对APP代码逻辑的一种保护.原理是将应用文件进行某种形式的转换,包括不限于隐藏,混淆,加密等操作,进一步保护软件的利益不受损坏.总结主要有以下三方 ...

  4. Kubernetes(K8S) kubesphere 介绍

    使用 Kubeadm 部署 Kubernetes(K8S) 安装--附K8S架构图 官网地址:https://kubesphere.com.cn/ KubeSphere 是个全栈的Kubernetes ...

  5. [人脸活体检测] 论文: Learning Deep Models for Face Anti-Spoofing: Binary or Auxiliary Supervision

    Learning Deep Models for Face Anti-Spoofing: Binary or Auxiliary Supervision 论文简介 与人脸生理相关的rppG信号被研究者 ...

  6. 计算机网络之MAC和IP地址

    MAC地址 在局域网中,硬件地址,又称为物理地址或MAC地址. 目前现在的局域网中实际上使用的都是6字节的MAC地址,所以每一个以太网设备都具有唯一的MAC地址. MAC地址的格式 假设传输使用的是I ...

  7. Python NumPy 广播(Broadcast)

    广播(Broadcast)是 numpy 对不同形状(shape)的数组进行数值计算的方式, 对数组的算术运算通常在相应的元素上进行. 如果两个数组 a 和 b 形状相同,即满足 a.shape == ...

  8. 2022-08-22:给定一个数组arr,长度为n,最多可以删除一个连续子数组, 求剩下的数组,严格连续递增的子数组最大长度。 n <= 10^6。 来自字节。5.6笔试。

    2022-08-22:给定一个数组arr,长度为n,最多可以删除一个连续子数组, 求剩下的数组,严格连续递增的子数组最大长度. n <= 10^6. 来自字节.5.6笔试. 答案2022-08- ...

  9. 2021-01-10:linux中,我要看某一个进程的并发,通过什么命令去查?

    福哥答案2021-01-10:[答案来自此链接:](https://blog.csdn.net/sinat_31275315/article/details/108239492)方法一:PS在ps命令 ...

  10. 2021-06-20:已知一个消息流会不断地吐出整数 1~N,但不一定按照顺序依次吐出。如果上次打印的序号为i, 那么当i+1出现时,请打印 i+1 及其之后接收过的并且连续的所有数,直到1~N全部接

    2021-06-20:已知一个消息流会不断地吐出整数 1~N,但不一定按照顺序依次吐出.如果上次打印的序号为i, 那么当i+1出现时,请打印 i+1 及其之后接收过的并且连续的所有数,直到1~N全部接 ...