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的更多相关文章

  1. AtCoder Beginner Contest 132 解题报告

    前四题都好水.后面两道题好难. C Divide the Problems #include <cstdio> #include <algorithm> using names ...

  2. AtCoder Beginner Contest 132 F Small Products

    Small Products 思路: 整除分块+dp 打表发现,按整除分块后转移方向如下图所示,上面的块的前缀转移到下面的块 代码: #pragma GCC optimize(2) #pragma G ...

  3. AtCoder Beginner Contest 132 E - Hopscotch Addict

    bfs 位置+状态 just need to calculate min value(only it is useful), so O(1*x) 挺有趣的一道题... #include <cst ...

  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. RHadoop: REDUCE capability required is more than the supported max container capability in the cluster

    I have not used RHadoop. However I've had a very similar problem on my cluster, and this problem see ...

  2. MySQL 5.7 多源复制实践

    多源复制使用场景 数据分析部门会需要各个业务部门的部分数据做数据分析,这个时候就可以用到多源复制把各个主数据库的数据复制到统一的数据库中. 在从服务器进行数据汇总,如果我们的主服务器进行了分库分表的操 ...

  3. ActivityMQ消息中间件【待完成】

    1,MQ的引入 使用场景,将耗时的通知业务交给消息中间件[业务逻辑进行解耦] 使用消息中间件的逻辑交互 2,MQ的应用场景 首先消息中间件是一个异步处理 有两个关键点:①耗时:②业务的耦合度 案例1: ...

  4. 如何在含有json类型的字段上建立多列索引

    废话不多,直接上图 如 : 表结构如图           那么我想在这三个字段上建立一个唯一索引,目的是为了防止重复插入数据, 1.首先,说明一下 data中的json中,key为 tagID 和 ...

  5. cordova 和 java ( JDK ) 和 android-studio (SDK)的初始安装和配置

    一:前言(2018) 之前封装APP都是用的HBuilder结合mui来封装的简单app,有空的时候想研究下之前的phonegap来封装app.然后遇到的问题还是蛮多的,毕竟之前没弄过. 下面的步骤主 ...

  6. 使用HTML CSS制作简易三角形和旗帜

    HTML:     <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  7. keras 切换后端 TensorFlow,cntk,theano

    参考 https://keras.io/#configuring-your-keras-backend https://keras.io/backend/ Switching from one bac ...

  8. 一步一步教你实现iOS音频频谱动画(二)

    如果你想先看看最终效果再决定看不看文章 -> bilibili 示例代码下载 第一篇:一步一步教你实现iOS音频频谱动画(一) 本文是系列文章中的第二篇,上篇讲述了音频播放和频谱数据计算,本篇讲 ...

  9. MyBatis-Spring 之SqlSessionFactoryBean

    要创建工厂 bean,放置下面的代码在 Spring 的 XML 配置文件中: <bean id="sqlSessionFactory" class="org.my ...

  10. 《基于Scyther的秘钥建立协议设计》-------摘抄整理

    本篇论文额主要创新点:   利用Scyther软件,通过对一个不安全的秘钥建立协议逐步添加并验证安全属性,最终建立一个安全的秘钥建立协议. 通过形式化分析软件设计秘钥建立协议课可以提高协议设计效率,减 ...