补题链接:Here

A - Don't be late

题意:高桥(Takahashi )现在要去距离家 \(D\) 米的地方面基,请问如果以最高速度 \(S\) 能否再 \(T\) 时刻准时到达?

\(cout << (d / s <= t ? "Yes" : "No");\)

注意点使用 float

B - Substring

注意到 S T 长度很小,所有可以枚举

int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
string s, t;
cin >> s >> t;
int n = s.size(), m = t.size();
int ans = m;
for (int start = 0; start <= n - m; ++start) {
int cnt = 0;
for (int i = 0; i < m; ++i)
if (t[i] != s[start + i]) cnt++;
ans = min(ans, cnt);
}
cout << ans << "\n";
return 0;
}

C - Sum of product of pairs

维护后缀和,记得取模即可

using ll = long long;
const ll mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
ll a[n + 1], lst[n + 2] = {};
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = n; i >= 1; --i) {
lst[i] = (lst[i + 1] % mod + (i == n ? 0 : a[i + 1]) % mod) % mod;
}
ll ans = 0;
for (int i = 1; i < n; ++i) {
ans = (ans + a[i] * lst[i] + mod) % mod;
}
cout << ans % mod << "\n";
return 0;
}

D - Friends

题意:给定 n 个人的 m 对朋友关系,现在进行最小化分组要是每个组里都没有互相认识的人,

思路:并查集,求出最大连通分量即可

  • \(\mathcal{O}(NlogN)\)
const int N = 2e5 + 7;
int f[N], Siz[N];
int find(int x) {
return f[x] == x ? x : f[x] = find(f[x]);
}
void merge(int x, int y) {
x = find(x), y = find(y);
if (x != y)
f[x] = y, Siz[y] += Siz[x];
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int n, m;
for (int i = 1; i <= N - 1; ++i) f[i] = i, Siz[i] = 1;
cin >> n >> m;
while (m--) {
int x, y;
cin >> x >> y;
merge(x, y);
}
sort(Siz, Siz + n + 1);
cout << Siz[n];
return 0;
}

E - Coprime

质因数分解,统计含有每个质因子的数的个数,然后求出最大的个数。如果这个值为 \(1\),说明两两互质;如果这个值小于\(N\),说明总体互质。

int cnt[1 << 20];
int all = 0;
bool isp[1 << 20];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
for (int i = 0, x; i < n; ++i) {
cin >> x;
cnt[x]++;
all = gcd(all, x);
}
bool f = true;
for (int i = 2; i < (1 << 20); ++i) {
int sum = 0;
for (int j = i; j < (1 << 20); j += i) sum += cnt[j];
if (sum > 1) f = false;
}
cout << (f ? "pairwise coprime" : all == 1 ? "setwise coprime"
: "not coprime");
return 0;
}

AtCoder Beginner Contest 177

AtCoder Beginner Contest 177 (个人题解,C后缀和,D并查集,E质因数分解)的更多相关文章

  1. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

  2. KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解

    KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...

  3. AtCoder Beginner Contest 177 E - Coprime (数学)

    题意:给你\(n\)个数,首先判断它们是否全都__两两互质__.然后再判断它们是否全都互质. 题解:判断所有数互质很简单,直接枚举跑个gcd就行,关键是第一个条件我们要怎么去判断,其实我们可以对所有数 ...

  4. AtCoder Beginner Contest 177 D - Friends (并查集)

    题意:有\(n\)个人,给你\(m\)对朋友关系,朋友的朋友也是朋友,现在你想要将他们拆散放到不同的集合中,且每个集合中的人没有任何一对朋友关系,问最少需要多少集合. 题解:首先用并查集将朋友关系维护 ...

  5. AtCoder Beginner Contest 089完整题解

    A - Grouping 2 Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement There a ...

  6. AtCoder Beginner Contest 177

    比赛链接:https://atcoder.jp/contests/abc177/tasks A - Don't be late #include <bits/stdc++.h> using ...

  7. 2018.09.08 AtCoder Beginner Contest 109简要题解

    比赛传送门 水题大赛? 全是水题啊!!! T1 ABC333 就是判断是不是两个数都是奇数就行了. 代码: #include<bits/stdc++.h> using namespace ...

  8. Atcoder Beginner Contest 138 简要题解

    D - Ki 题意:给一棵有根树,节点1为根,有$Q$次操作,每次操作将一个节点及其子树的所有节点的权值加上一个值,问最后每个节点的权值. 思路:dfs序再差分一下就行了. #include < ...

  9. AtCoder Beginner Contest 148 题解

    目录 AtCoder Beginner Contest 148 题解 前言 A - Round One 题意 做法 程序 B - Strings with the Same Length 题意 做法 ...

  10. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

随机推荐

  1. [Codechef REBXOR]Nikitosh and xor (Trie,异或)

    题目传送门 分析:首次考虑暴力枚举 \(l_{1},r_{1},l_{2},r_{2}\),配合前缀和时间复杂度 \(O(N^{4})\),需要想办法优化.对于这种两段区间不重合的,我们考虑枚举两段区 ...

  2. h5移动端使用video实现拍照、上传文件对象、选择相册,做手机兼容。

    html部分 <template> <div class="views"> <video style="width: 100vw; heig ...

  3. Kafka集群调优+能力探底

    一.前言 我们需要对4个规格的kafka能力进行探底,即其可以承载的最大吞吐:4个规格对应的单节点的配置如下: 标准版: 2C4G 铂金版: 4C8G 专业版: 8C16G 企业版: 16C32G 另 ...

  4. Android 图表开源库调研及使用示例

    原文地址: Android图表开源库调研及使用示例 - Stars-One的杂货小窝 之前做的几个项目都是需要实现图表统计展示,于是做之前调研了下,做下记录 概述 AAChartCore-Kotlin ...

  5. Tensorflow2.0:使用Keras自定义网络实战

    tensorflow2.0建议使用tf.keras作为构建神经网络的高级API 接下来我就使用tensorflow实现VGG16去训练数据 背景介绍: 2012年 AlexNet 在 ImageNet ...

  6. TypeError: 'module' object is not callable (pytorch在进行MNIST数据集预览时出现的错误)

    在使用pytorch在对MNIST数据集进行预览时,出现了TypeError: 'module' object is not callable的错误: 上报错信息图如下: 从图中可以看出,报错位置为第 ...

  7. MySQL日期时间加|减法

    日期加法 select date_add(curdate(), interval N SECOND); -- 加N秒 select date_add(curdate(), interval N MIN ...

  8. 前端传递Base64字符串,后端转流存入OSS

    工具类 public static BufferedInputStream base64Convert(String base64) { // 解码 base64 = base64.split(&qu ...

  9. HDU-2159 二维背包

    最近xhd正在玩一款叫做FATE的游戏,为了得到极品装备,xhd在不停的杀怪做任务.久而久之xhd开始对杀怪产生的厌恶感,但又不得不通过杀怪来升完这最后一级.现在的问题是,xhd升掉最后一级还需n的经 ...

  10. Netty源码学习9——从Timer到ScheduledThreadPoolExecutor到HashedWheelTimer

    系列文章目录和关于我 一丶前言 之前在学习netty源码的时候,经常看netty hash时间轮(HashedWheelTimer)的出现,时间轮作为一种定时调度机制,在jdk中还存在Timer和Sc ...