比赛链接:https://atcoder.jp/contests/abc177/tasks

A - Don't be late

#include <bits/stdc++.h>
using namespace std;
int main() {
int d, t, s;
cin >> d >> t >> s;
cout << (t * s >= d ? "Yes" : "No") << "\n";
}

B - Substring

#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
int ans = INT_MAX;
for (int i = 0; i + t.size() <= s.size(); i++) {
int change = 0;
for (int j = 0; j < t.size(); j++)
if (s[i + j] != t[j])
++change;
ans = min(ans, change);
}
cout << ans << "\n";
}

C - Sum of product of pairs

#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<long long> pref(n);
for (int i = 0; i < n; i++) {
if (i == 0) pref[i] = a[i];
else pref[i] = pref[i - 1] + a[i];
}
long long ans = 0;
for (int i = 0; i < n; i++) {
ans += a[i] * ((pref[n - 1] - pref[i]) % mod) % mod;
ans %= mod;
}
cout << ans << "\n";
}

D - Friends

原题hdu 1856

#include <bits/stdc++.h>
using namespace std;
constexpr int N = 2e5 + 100; int fa[N], son_num[N]; int Find(int x) {
if (fa[x] == x) return fa[x];
else return fa[x] = Find(fa[x]);
} void Union(int x, int y) {
x = Find(x);
y = Find(y);
if (x != y) {
fa[y] = x;
son_num[x] += son_num[y];
}
} void Init() {
for (int i = 0; i < N; i++) {
fa[i] = i;
son_num[i] = 1;
}
} int main() {
Init();
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
Union(x, y);
}
cout << *max_element(son_num, son_num + N) << "\n";
}

E - Coprime

#include <bits/stdc++.h>
using namespace std;
constexpr int N = 1e6 + 100; int p[N]; void init() {
for (int i = 2; i < N; i++) {
if (p[i]) continue;
for (int j = i; j < N; j += i) {
p[j] = i;
}
}
} int main() {
init();
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<set<int>> div(n);
for (int i = 0; i < n; i++) {
for (int j = a[i]; p[j] != 0; j /= p[j]) {
div[i].insert(p[j]);
}
}
bool pairwise = true;
map<int, int> cnt;
for (int i = 0; i < n; i++) {
for (const auto &x : div[i]) {
if (++cnt[x] >= 2)
pairwise = false;
}
}
bool setwise = false;
int gcd = 0;
for (int i = 0; i < n; i++)
gcd = __gcd(gcd, a[i]);
if (gcd == 1)
setwise = true;
if (pairwise)
cout << "pairwise coprime" << "\n";
else if (setwise)
cout << "setwise coprime" << "\n";
else
cout << "not coprime" << "\n";
}

AtCoder Beginner Contest 177的更多相关文章

  1. AtCoder Beginner Contest 177 题解

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

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

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

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

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

  4. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  5. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  6. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  7. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  8. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  9. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

随机推荐

  1. oracle 常用指令(持续更新中....)

    1. 查看所有表空间大小 select tablespace_name,sum(bytes)/1024/1024 from dba_data_files group by tablespace_nam ...

  2. Lock锁 精讲

    1.为什么需要Lock 为什么synchronized不够用,还需要Lock Lock和synchronized这两个最常见的锁都可以达到线程安全的目的,但是功能上有很大不同. Lock并不是用来代替 ...

  3. 如何使用 VS Code开发.NET Core应用程序

    Visual Studio Code(VS Code)是Microsoft为Windows,Linux和Mac操作系统开发的免费,跨平台,轻量级的源代码编辑器,它是源代码编辑器,而Visual Stu ...

  4. 2020周阳SpringCloud完整版笔记--一

    微服务架构入门 微服务 的概念最早产生于Martin Fowler在2014年的一篇论文中. 微服务架构是一种架构模式,他提倡将单一应用程序划分成一组小的服务,服务与服务之间互相协调.相互配合,为用户 ...

  5. 使用Jenkins+Blue Ocean 持构建自动化部署之安卓源码打包、测试、邮件通知

    什么是BlueOcean? BlueOcean重新考虑了Jenkins的用户体验.BlueOcean由Jenkins Pipeline设计,但仍然兼容自由式工作,减少了团队成员的混乱,增加了清晰度. ...

  6. python函数1-函数基础

  7. 【Linux】rsync错误解析

    rsync: Failed to exec ssh: No such file or directory (2) rsync error: error in IPC code (code 14) at ...

  8. 【ORACLE错误】SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled

    执行set autotrace traceonly的时候,报错 SQL> set autotrace traceonly SP2-0618: Cannot find the Session Id ...

  9. ctfhub技能树—信息泄露—PHPINFO

    打开靶机 查看页面,是PHP info界面 只有这一个页面,查找一下有没有flag 拿到flag 浅谈ctf中phpinfo需要关注的点(转自先知社区) 1 https://xz.aliyun.com ...

  10. javascript判断浏览器访问,刷新,返回

    话不多说,直接上 if (window.performance.navigation.type === 0/* 正常访问 */) { // 你要干的事 } else if (window.perfor ...