AtCoder Beginner Contest 132
Contest Info
[Practice Link](https://atcoder.jp/contests/abc132/tasks)
| Solved | A | B | C | D | E | F |
|---|---|---|---|---|---|---|
| 6/6 | O | O | O | O | Ø | O |
- O 在比赛中通过
- Ø 赛后通过
- ! 尝试了但是失败了
- - 没有尝试
Solutions
A. Fifty-Fifty
#include <bits/stdc++.h>
using namespace std;
int main() {
string s; cin >> s;
sort(s.begin(), s.end());
s.erase(unique(s.begin(), s.end()), s.end());
cout << (((int)s.size() == 2) ? "Yes" : "No") << "\n";
return 0;
}
B. Ordinary Number
#include <bits/stdc++.h>
using namespace std;
#define N 50
int n, a[N];
int main() {
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i);
}
int res = 0;
for (int i = 2; i < n; ++i) {
int f = a[i] < a[i - 1];
int g = a[i] < a[i + 1];
if (f ^ g) {
++res;
}
}
printf("%d\n", res);
}
return 0;
}
C. Divide the Problems
#include <bits/stdc++.h>
using namespace std;
#define N 100010
int n, a[N];
int main() {
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i);
}
sort(a + 1, a + 1 + n);
int mid = n / 2;
if (a[mid] == a[mid + 1]) {
puts("0");
} else {
printf("%d\n", a[mid + 1] - a[mid]);
}
}
return 0;
}
D. Blue and Red Balls
题意:
有\(K\)个蓝球,\(N - K\)个红球,询问将蓝球分成\(i(1 \leq i \leq k)\)堆,中间用红球隔开的方案数分别是多少?
思路:
考虑先将\(k\)个蓝球分成\(i\)堆,然后每堆后面跟着一个红球,然后就有\(i + 1\)个空隙,剩下的红球相当于要放入\(i + 1\)个空箱中,允许空箱的经典问题。
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 2010
const int p = 1e9 + 7;
int n, k;
ll fac[N], inv[N];
ll qmod(ll base, ll n) {
ll res = 1;
while (n) {
if (n & 1) {
res = res * base % p;
}
base = base * base % p;
n >>= 1;
}
return res;
}
ll C(int n, int m) {
if (n < m) return 0;
return fac[n] * inv[m] % p * inv[n - m] % p;
}
ll f(int n, int i, int k) {
ll remind = n - k;
if (n - k < i - 1) {
return 0;
}
remind -= i - 1;
return C(k - 1, i - 1) * C(i + remind, i) % p;
}
int main() {
fac[0] = 1;
for (int i = 1; i <= 2000; ++i) {
fac[i] = fac[i - 1] * i % p;
}
inv[2000] = qmod(fac[2000], p - 2);
for (int i = 2000; i >= 0; --i) {
inv[i - 1] = inv[i] * i % p;
}
while (scanf("%d%d", &n, &k) != EOF) {
for (int i = 1; i <= k; ++i) {
printf("%lld\n", f(n, i, k));
}
}
return 0;
}
E. Hopscotch Addict
题意:
求\(S\)到\(T\)的最短路,并且要满足其长度是\(3\)的倍数。
思路:
\(dis[i][j]\)表示到第\(i\)个点,长度模\(3\)的值为\(j\)的最短路是多少,然后跑Dijkstra即可。
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define N 100010
int n, m, s, t;
vector <vector<int>> G;
struct node {
int u, w;
node() {}
node (int u, int w) : u(u), w(w) {}
bool operator < (const node &other) const {
return w > other.w;
}
};
int dis[N][3], used[N][3];
void BFS() {
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < 3; ++j) {
dis[i][j] = INF;
used[i][j] = 0;
}
}
dis[s][0] = 0;
priority_queue <node> pq;
pq.push(node(s, 0));
while (!pq.empty()) {
int u = pq.top().u, w = pq.top().w; pq.pop();
if (used[u][w % 3]) continue;
used[u][w % 3] = 1;
for (auto v : G[u]) {
if (dis[v][(w + 1) % 3] > w + 1) {
dis[v][(w + 1) % 3] = w + 1;
pq.push(node(v, w + 1));
}
}
}
}
int main() {
while (scanf("%d%d", &n, &m) != EOF) {
G.clear(); G.resize(n + 1);
for (int i = 1, u, v; i <= m; ++i) {
scanf("%d%d", &u, &v);
G[u].push_back(v);
}
scanf("%d%d", &s, &t);
BFS();
if (dis[t][0] == INF) puts("-1");
else {
printf("%d\n", dis[t][0] / 3);
}
}
return 0;
}
F. Small Products
题意:
构造一个长度为\(k\)的,并且相邻两数之积不超过\(N\)的序列的方案数是多少?
思路:
\(f[i][j]\)表示到第\(i\)位,当前位为\(j\)的方案数是多少。
暴力\(DP\)显然不行。
但是我们考虑我们每次对于\(j\)转移的都是\(\sum\limits_{j = 1}^{N / j} f[i - 1][j]\),考虑到\(N / j\)的取值只有\(2\sqrt{N}\)种,所以只需要存\(k \cdot 2\sqrt{N}\)种状态。转移即可。
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 110
#define M 100010
#define pii pair <int, int>
#define fi first
#define se second
const ll p = 1e9 + 7;
int n, k;
ll f[N][M];
pii g[M];
map <int, int> mp;
int main() {
while (scanf("%d%d", &k, &n) != EOF) {
memset(f, 0, sizeof f);
mp.clear();
int m = 0;
for (int i = 1, j; i <= k; i = j + 1) {
j = k / (k / i);
g[++m] = pii(j, j - i + 1);
mp[j] = m;
}
for (int i = 1; i <= m; ++i) {
f[1][i] = (f[1][i - 1] + g[i].se) % p;
}
for (int i = 2; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
f[i][j] = (f[i][j - 1] + 1ll * g[j].se * f[i - 1][mp[k / g[j].fi]] % p) % p;
}
}
printf("%lld\n", f[n][m]);
}
return 0;
}
AtCoder Beginner Contest 132的更多相关文章
- AtCoder Beginner Contest 132 解题报告
前四题都好水.后面两道题好难. C Divide the Problems #include <cstdio> #include <algorithm> using names ...
- AtCoder Beginner Contest 132 F Small Products
Small Products 思路: 整除分块+dp 打表发现,按整除分块后转移方向如下图所示,上面的块的前缀转移到下面的块 代码: #pragma GCC optimize(2) #pragma G ...
- AtCoder Beginner Contest 132 E - Hopscotch Addict
bfs 位置+状态 just need to calculate min value(only it is useful), so O(1*x) 挺有趣的一道题... #include <cst ...
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 052
没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 136
AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...
- AtCoder Beginner Contest 137 F
AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
随机推荐
- 游记-pkupc&cts2019
Day0 和boshi.Rayment组的队,昨天听学长说这次比赛可以加学分,他们信科的大部分人都会参加,估摸有两百多支队伍--然而奖品只有不到一百份 我要奖品呐! 上午十一点半到的北京,拉着行李提着 ...
- webapi IHttpActionResult无引用和config.MapHttpAttributeRoutes()无引用解决办法
1. 打开NuGet,打开方法 工具->库程序包管理器->程序包管理器控制台,如下图所示: 2. 输入如下命令Install-Package Microsoft.AspNet.WebApi ...
- 排序算法原理及代码实现(c#)
1.插入排序 把第一个元素看做已排序数组放在有序数组中,从第二个元素开始,依次把无序数组元素取出和有序数组中的元素逐个比较,并放在有序数组的正确位置上. /// <summary> /// ...
- 【原创】大叔经验分享(86)hive和mysql数据互导
hive和mysql数据互导,首先想到的是sqoop,并且可以和调度框架(比如oozie等)配合配置定时任务,还有一种更简单的方式是通过spark-sql: CREATE OR REPLACE TEM ...
- JS基础_this
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- React中setState如何修改深层对象?
在React中经常会使用到setState,因为在react生态中,state就是一切.在开发过程中,时长会在state中遇到一些比较复杂的数据结构,类似下面这样的: 这时需要我们修改list中obj ...
- angular轮播图
还是直接上代码比较好 <!doctype html><html lang="en"><head> <meta charset=" ...
- el-select 可选择可输入
<el-select v-model="saveWardForm.wardCode" placeholder="" filterable @blur=&q ...
- macOS 在终端中使用 adb命令,每次都要source ~/.bash_profile 才生效
macOS下已经配置好Android开发环境,环境变量也添加了,但是在终端中使用adb命令每次都需要source .bash_profile之后才能识别, 否则就提示 zsh: command no ...
- UMI.js开发知识总结
五分钟掌握最小知识体系 本文阅读时间大概为5分钟,但是能让你了解基于UMI和DVA构建项目的最小知识体系,你可以粗略的浏览一下本文所提到的知识,在后续的讲解中都会多次重复提起,保证学习效率.由于现在前 ...