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. Codeforces 1245 D. Shichikuji and Power Grid

    传送门 经典的最小生成树模型 建一个点 $0$ ,向所有其他点 $x$ 连一条边权为 $c[x]$ 的边,其他任意两点之间连边,边权为 $(k_i+k_j)(\left | x_i-x_j\right ...

  2. 将迁移学习用于文本分类 《 Universal Language Model Fine-tuning for Text Classification》

    将迁移学习用于文本分类 < Universal Language Model Fine-tuning for Text Classification> 2018-07-27 20:07:4 ...

  3. ASP.NET WEB应用程序(.network4.5)MVC Razor视图引擎2 动态数据的呈现

    https://www.cnblogs.com/cynchanpin/p/7065098.html 在MVC3開始.视图数据能够通过ViewBag属性訪问.在MVC2中则是使用ViewData.MVC ...

  4. 冒泡(bubblesort)、选择排序、插入排序、快速排序

    冒泡排序(bubblesort) 特点:通过换位置的方式,一直向上冒泡 package main import "fmt" func bubbleSortAsc(arrayA [] ...

  5. vue之生命周期与导航守卫

    组件钩子函数: beforeCreate.created.beforeMount.mounted.beforeUpdate.updated.beforeDestroy.destoryed 还有两个特殊 ...

  6. 【微信网页直接下载app】微信跳转-微信浏览器中直接唤起本地浏览器和App

    文档传送门:https://github.com/EthanOrange/wechat-redirect demo: http://wxredirect.jslab.fun/call-app

  7. 案例:selenium实现登录处理弹窗

    func.py https://www.cnblogs.com/andy9468/p/10899508.html main.py中 # 导入webdriver import os import tim ...

  8. SmartBinding实现DataSet与ListView的绑定及同步显示

    kbmMW 5.10.10发布了,这个版本解决了我提出的问题,当对DataSet增删记录时,ListView能够同步显示.下面看看具体的实现代码. 为了解决上面的问题,作者为IkbmMWBinding ...

  9. C# Winfrom 窗体上动态生成控件慢处理

    处理方式:布局挂起 panelContent.SuspendLayout(); panelContent.ResumeLayout(); private void button1_Click(obje ...

  10. .NET Core中使用水印

    .NET Core中使用水印 在项目中,我需要给上传的图片添加水印,通过网上查找针对.NET Core 的找到两个方案: 使用 CoreCompat.System.Drawing 及用于非Window ...