比赛链接

A

题解

知识点:模拟。

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

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

代码

#include <bits/stdc++.h>
#define ll long long using namespace std; bool solve() {
int a, b, c;
cin >> a >> b >> c;
if (a + b == c || a + c == b || b + c == a) cout << "YES" << '\n';
else cout << "NO" << '\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

题解

知识点:枚举。

查重即可。

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

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

代码

#include <bits/stdc++.h>
#define ll long long using namespace std; bool solve() {
int n;
cin >> n;
set<int> st;
bool ok = 1;
for (int i = 1;i <= n;i++) {
int x;
cin >> x;
if (st.count(x)) ok = 0;
st.insert(x);
}
if (ok) cout << "YES" << '\n';
else cout << "NO" << '\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;
}

C

题解

知识点:贪心。

行红,列蓝别搞错。

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

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

代码

#include <bits/stdc++.h>
#define ll long long using namespace std; char dt[10][10];
bool solve() {
for (int i = 1;i <= 8;i++)
for (int j = 1;j <= 8;j++)
cin >> dt[i][j];
for (int i = 1;i <= 8;i++) {
bool ok = 1;
for (int j = 1;j <= 8;j++) ok &= dt[i][j] == 'R';
if (ok) {
cout << 'R' << '\n';
return true;
}
}
for (int j = 1;j <= 8;j++) {
bool ok = 1;
for (int i = 1;i <= 8;i++) ok &= dt[i][j] == 'B';
if (ok) {
cout << 'B' << '\n';
return true;
}
}
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

题解

知识点:枚举,数论。

注意到 \(a_i \in [1,1000]\) ,因此贪心地记录 \(a_i\) 最后一次的位置,枚举 \([1,1000]\) 每个数的组合即可。

时间复杂度 \(O(n+1000^2)\)

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

代码

#include <bits/stdc++.h>
#define ll long long using namespace std; int vis[1007];
bool solve() {
int n;
cin >> n;
memset(vis, 0, sizeof(vis));
for (int i = 1;i <= n;i++) {
int x;
cin >> x;
vis[x] = max(vis[x], i);
}
int ans = -1;
for (int i = 1;i <= 1000;i++) {
if (!vis[i]) continue;
for (int j = i;j <= 1000;j++) {
if (!vis[j]) continue;
if (__gcd(i, j) == 1) ans = max(ans, vis[i] + vis[j]);
}
}
cout << 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

题解

知识点:二分,前缀和,枚举。

预处理前缀和方便输出答案,前缀最大值方便找到最大合法段,然后二分查询第一个大于 \(x\) 的位置 \(i\) ,则 \([1,i-1]\) 都可以。

时间复杂度 \(O(n+q\log n)\)

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

代码

#include <bits/stdc++.h>
#define ll long long using namespace std; ll a[200007], mx[200007];
bool solve() {
int n, q;
cin >> n >> q;
for (int i = 1;i <= n;i++) {
cin >> a[i];
mx[i] = max(mx[i - 1], a[i]);
a[i] += a[i - 1];
}
while (q--) {
int x;
cin >> x;
int pos = upper_bound(mx + 1, mx + 1 + n, x) - mx - 1;
cout << a[pos] << ' ';
}
cout << '\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;
}

F

题解

知识点:贪心。

我们可以任意排列且 \(s,t\) 初始有 a ,那么如果 \(t\) 具有超过 a 的字母,那么一定可以有 \(s<t\) ;否则,如果 \(s\) 也没有超过 a 的字母且 \(s\) 长度小于 \(t\) ,那么一定可以有 \(s<t\) ;否则一定有 \(t<s\) 。

时间复杂度 \(O(q+\sum |s|)\)

空间复杂度 \(O(|s|)\)

代码

#include <bits/stdc++.h>
#define ll long long using namespace std; bool solve() {
int q;
cin >> q;
ll cnts = 0, cntt = 0;
bool sbad = 0, tgood = 0;
while (q--) {
int d, k;
string x;
cin >> d >> k >> x;
if (d == 1) {
for (auto ch : x) {
cnts += k * (ch == 'a');
sbad |= ch != 'a';
}
}
else {
for (auto ch : x) {
cntt += k * (ch == 'a');
tgood |= ch != 'a';
}
}
if (tgood) cout << "YES" << '\n';
else if (!sbad && cnts < cntt) cout << "YES" << '\n';
else cout << "NO" << '\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;
}

G

题解

知识点:位运算,贪心,枚举。

用 \(val\) 记录目前哪个位置还缺 \(1\) 。每次枚举没有取过的数字,找到一个数 \(a[pos]\) 使 a[pos] & val 最大,表示有效位组成最大的数字。然后取出来,并通过 val &= ~a[pos] 把 \(val\) 中对应的 \(1\) 删除(把 \(a[pos]\) 取反,原来的 \(1\) 现在都为 \(0\) ,然后与 \(val\) 就能删掉 \(val\) 对应的 \(1\))。最后把 \(a[pos]\) 交换到末尾的有效数字,实现逻辑删除。

因为 int 有 \(31\) 位,每次删除删的是结果最大的,最多删除 \(31\) 次就能达到这个序列或的最大值。

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

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

代码

#include <bits/stdc++.h>
#define ll long long using namespace std; int a[200007];
bool solve() {
int n;
cin >> n;
for (int i = 1;i <= n;i++) cin >> a[i];
int val = ~(1 << 31);
for (int i = 1;i <= min(31, n);i++) {
int pos = 1;
for (int j = 1;j <= n - i + 1;j++) {
if ((val & a[j]) > (val & a[pos])) pos = j;
}
cout << a[pos] << ' ';
val &= ~a[pos];
swap(a[n - i + 1], a[pos]);
}
for (int i = 1;i <= n - min(31, n);i++) cout << a[i] << ' ';
cout << '\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 #827 (Div. 4) 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 /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...

随机推荐

  1. 052_末晨曦Vue技术_处理边界情况之程序化的事件侦听器

    程序化的事件侦听器 点击打开视频讲解更详细 现在,你已经知道了 $emit 的用法,它可以被 v-on 侦听,但是 Vue 实例同时在其事件接口中提供了其它的方法.我们可以: 通过 $on(event ...

  2. python中的画图神器——turtle模块

    turtle库的基础命令介绍(1)画布画布cancas是绘图区域,可以设置它的大小和初始位置 turtle.screensize(1000,600,'red') 大小的设置 turtle.setup( ...

  3. C#基础_枚举

    一.在学习枚举之前,首先来听听枚举的优点. 1.枚举能够使代码更加清晰,它允许使用描述性的名称表示整数值. 2.枚举使代码更易于维护,有助于确保给变量指定合法的.期望的值. 3.枚举使代码更易输入. ...

  4. mac M1通过homebrew安装python3报错Error: Command failed with exit 128: git

    fatal: not in a git directoryError: Command failed with exit 128: git 只需要运行 git config --global --ad ...

  5. 【java】学习路线5-public和private、构造方法、this关键字、封装对象、static关键字、main方法结构解析

    //一个教务管理系统//知识点清单/*public & private 的区别一个是公开的,一个是私有的,作用域不一样,访问的权限不一样咯如果是用private修饰,则调用者只可以是在当前的作 ...

  6. Javascript之异步循环打印这道小题

    这道题,我相信很多前端从业者都知道,它本质上来说并不复杂,但是却可以有很深远的扩展,最终核心的主题其实就是异步的遍历,其中对于题目的初级解法,还涉及到一些作用域的知识.那么我们以最容易理解的解法入手, ...

  7. Navicat破解版下载安装

    不要再去搜索尝试其他人的破解方式,真是浪费时间!!!网上的所谓"Navicat Premium 15 破解补丁",使用version.dll等破解的亲测不可用,还有一种使用&quo ...

  8. 不当使用 union all 导致的SQL解析时间过长的问题优化

    在帮助用户优化应用过程中,发现用户大量使用union all 导致SQL解析非常缓慢的问题.考虑到这个问题很有代表意义,我觉得很有必要对于问题进行总结. 一.用户例子 WITH company_use ...

  9. Linux 常用脚本命令

    Linux 常用(脚本)命令 1. 统计目录下文件个数 ll |grep "^-"|wc -1 解释 grep "^-"表示抓取以-开头的行(其他忽略)

  10. torch.stack()与torch.cat()

    torch.stack():http://www.45fan.com/article.php?aid=1D8JGDik5G49DE1X torch.stack()个人理解:属于先变形再cat的操作,所 ...