A

#include <iostream>

using namespace std;

int main() {
int a, b, c;
cin >> a >> b >> c;
for(int i = 1; i <= 1000; i ++ ) {
if(c * i >= a && c * i <= b) {
cout << c * i ;
return 0;
}
if(c * i > b) break;
}
cout << "-1";
return 0; return 0;
}

B

#include <iostream>
#include <algorithm>
#include <cstring> #define LL long long
using namespace std; int main() {
string a, b;
int k; cin >> k >> a >> b;
LL cnt1 = 0, cnt2 = 0;
// cout << a << b << endl;
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
LL res = 1;
for(int i = 0; a[i]; i ++ ) {
int p = a[i] - '0';
cnt1 += p * res;
res *= k;
}
res = 1;
for(int i = 0; b[i]; i ++ ) {
int p = b[i] - '0';
cnt2 += p * res;
res *= k;
}
// cout << cnt1 << ' ' << cnt2 << endl;
cout << cnt1 * cnt2; return 0;
}

C

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector> #define LL long long
using namespace std; int main() {
int n; cin >> n;
vector<int> a(n);
LL ans = 0;
for(int &x: a) {
cin >> x;
ans += x;
}
LL p; cin >> p; LL res = p / ans * n;
LL pp = 0;
p %= ans; for(int i = 0; i < n; i ++ ) {
pp += a[i];
if(pp > p) {
cout << res + i + 1 << endl;
return 0;
}
} return 0;
}

D

线性DP

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#define pb push_back #define mod(x) (x) % MOD
#define LL long long using namespace std; const int MOD = 998244353, N = 1e5 + 10; LL cnt[10];
int n, a[N]; int main() {
cin >> n;
for(int i = 0; i < n; i ++ ) cin >> a[i];
vector<LL> p(10, 0), q(10, 0);
q[a[0]] = 1;
for(int i = 1; i < n; i ++ ) {
// p = q;
for(int j = 0; j < 10; j ++ ) {
p[j] = q[j] % MOD;
q[j] = 0;
}
for(int j = 0; j < 10; j ++ ) {
q[(j + a[i]) % 10] = mod(q[(j + a[i]) % 10] + p[j]);
q[(j * a[i]) % 10] = mod(q[(j * a[i]) % 10] + p[j]);
} }
for(int i = 0; i < 10; i ++ ) {
cout << q[i] % MOD << endl;
} return 0;
}

E

对于每个节点形成的链有两种可能

  • 这个节点是上端点
  • 这个节点是中转节点



    对于1号节点
  • 第一种有链:421、521、631、731
  • 第二种有链:213、4213、42137....

这样枚举可以不重不漏的找出所有的长度固定的链

而且,对于每个节点第一种有\(2^{n+1}\)个(正向逆向要重复计数),第二种有\((d-1)*{2^{d-1}}\)个

当然有的节点可能不存在那么多,也就是当剩余的层数不足d的时候,我们就需要一层一层的拓展

比如说往下扩展一层就多了 $2 * {2^{d-2}} $ 即 左边的层数所具有的节点 * 右边层数所具有的节点 永远都是 \(2^{d-1}\)

因此还剩多少层我就就会加多少个 \(2^{d-1}\)

AC_CODE

#include <bits/stdc++.h>
#define mod(x) ((x) % MOD)
#define LL long long using namespace std; const int N = 2e6 + 10, MOD = 998244353; LL num[N]; int main() {
// pre
num[0] = 1;
for(int i = 1; i < N; i ++ )
num[i] = mod(num[i - 1] * 2);
LL ans = 0;
LL n, d; cin >> n >> d; for(int i = 0; i < n; i ++ ) {
LL cnt = num[i];
LL mx = n - i - 1;
if(mx >= d) {
ans = mod(ans + mod(num[d + 1] * cnt)); // 求出以第i层的节点为 链的端点的所有个数
ans = mod(ans + mod(num[d - 1] * mod((d - 1) * cnt)));// 求出以第i层的节点为 链的转折点的所有个数
//转折过后必须向下转折 可以不重不漏
} else if(2 * mx >= d) {
ans = mod(ans + mod(mod(num[d - 1] * cnt) * (2 * mx - d + 1)));
//求出以第i层的节点为 链的转折点的所有个数 因为不可以为 链的端点
} else break;
}
cout << mod(ans) << endl; return 0;
}

F

思路

先求出以1号节点为起点,其他的点到1号点的距离,然后对于1号点子节点,我们再继续求以这个点为起点的路径长度的时候

我们可以把其他的点分为两种

  • 一种是以此点为根的点
  • 一种不是以此点为根的点

对于第一种,每条路径长度减去1就是我们想知道的路径长度,第二种则需要加上1

整理一下会发现就是 ans[j] = ans[u] + (n - size(j)) - size(j); (u是j的根节点)

因此可以用树形DP解决这个问题

AC_CODE

#include <iostream>
#include <cstring>
#define LL long long using namespace std; const int N = 2e5 + 10, M = N << 1; int h[N], e[M], ne[M], idx;
int n;
LL ans[N], s[N]; void add(int a, int b) {
e[idx] = b;
ne[idx] = h[a];
h[a] = idx ++;
} int dfs(int u, int fa, int cnt) {
ans[1] += cnt;
int res = 1;
for(int i = h[u]; ~i; i = ne[i]) {
int j = e[i];
if(j == fa)
continue;
res += dfs(j, u, cnt + 1);
}
s[u] = res;
return res;
} void dfs1(int u, int fa) {
for(int i = h[u]; ~i; i = ne[i]) {
int j = e[i];
if(j == fa)
continue;
ans[j] = ans[u] + n - 2 * s[j];
dfs1(j, u);
}
} int main() {
memset(h, -1, sizeof h);
scanf("%d", &n);
for(int i = 1; i < n; i ++ ) {
int u, v;
scanf("%d%d", &u, &v);
add(u, v); add(v, u);
}
dfs(1, -1, 0);
dfs1(1, -1);
for(int i = 1; i <= n; i ++ )
printf("%lld\n", ans[i]);
return 0;
}

AtCoder Beginner Contest 220 A-F的更多相关文章

  1. AtCoder Beginner Contest 238 A - F 题解

    AtCoder Beginner Contest 238 \(A - F\) 题解 A - Exponential or Quadratic 题意 判断 \(2^n > n^2\)是否成立? S ...

  2. AtCoder Beginner Contest 220部分题(G,H)题解

    刚开始的时候被E题卡住了,不过发现是个数学题后就开始使劲推式子,幸运的是推出来了,之后的F题更是树形DP换根的模板吧,就草草的过了,看了一眼G,随便口胡了一下,赶紧打代码,毕竟时间不多了,最后也没打完 ...

  3. AtCoder Beginner Contest 131 Task F. Must Be Rectangular

    Score: 600 points Approach 固定横坐标 $x$,考虑横坐标为 $x$ 的竖直线上最多可以有几个点. Observations 若最初两条竖直线 $x_1$.$x_2$ 上都有 ...

  4. AtCoder Beginner Contest 137 F

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

  5. AtCoder Beginner Contest 136

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

  6. AtCoder Beginner Contest 154 题解

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

  7. AtCoder Beginner Contest 153 题解

    目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...

  8. AtCoder Beginner Contest 177 题解

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

  9. AtCoder Beginner Contest 161

    比赛链接:https://atcoder.jp/contests/abc161/tasks AtCoder Beginner Contest 161 第一次打AtCoder的比赛,因为是日本的网站终于 ...

随机推荐

  1. 【剑指Offer】删除链表中重复的结点 解题报告(Python)

    [剑指Offer]删除链表中重复的结点 解题报告(Python) 标签(空格分隔): 剑指Offer 题目地址:https://www.nowcoder.com/ta/coding-interview ...

  2. Generative Modeling by Estimating Gradients of the Data Distribution

    目录 概 主要内容 Langevin dynamics Score Matching Denoising Score Matching Noise Conditional Score Networks ...

  3. Defending Adversarial Attacks by Correcting logits

    目录 概 主要内容 实验 Li Y., Xie L., Zhang Y., Zhang R., Wang Y., Tian Q., Defending Adversarial Attacks by C ...

  4. SpringBoot集成MyBatis-Plus框架详细方法

    1.说明 本文详细介绍Spring Boot集成MyBatis-Plus框架的方法, 使用MySQL数据库进行测试, 包括完整的开发到测试步骤, 从一开始的Spring Boot工程创建, 到MySQ ...

  5. Git创建本地仓库

    使用Git创建本地仓库, 可以记录文本文件变化, 这里以自己的文章为例, 利用TortoiseGit工具创建一个本地Git仓库. 1. 切换到需要创建仓库的目录下, 比如:D:\MyDoc\Devel ...

  6. python自动化测试框架的unittest与pytest前后置条件的区别

    前言: 笔者先试有用过unittest的前后置条件和pytest的前后置条件,觉得pytest的前后置条件比unittest的要简洁.方便很多.不过在使用unittest的前后置条件时,已经觉得在和每 ...

  7. Samba服务器搭建与配置

    Samba服务简介Samba的起源:对于windows的网上邻居来讲,共享文件的方式用的是SMB和CIFS协议以及NETBIOS协议Linux/Unix之间用的是NFS协议. ​ 但是Linux和Wi ...

  8. 解决ubuntu 18.04(桌面版)搜狗输入法不能正常使用的问题

    ubuntu下搜狗输入法的配置文件在~/.config目录下,一般有三个目录SogouPY.SogouPY.users.sogou-qimpanel 执行命令 $ cd ~/.config $ rm ...

  9. POJ3090Visible Lattice Points

    http://poj.org/problem?id=3090 对于此题,观测点的数目,从小规模开始观察,可以得到每一个点,由一根无限长的绳子,绕着原点旋转,得到的第一个点.换另外一个思路,每一个观察到 ...

  10. 基于Appium的APP自动化测试基础--美团APP的实例

    转:https://blog.csdn.net/Tigerdong1/article/details/80159156 前段时间用一种流行语言,一个主流工具,一个实用框架,写了一个美团app自动化测试 ...