Problem A - twiblr

直接输出 \(2A + 100 - B\)

Problem B - Almost GCD

这里暴力枚举即可

int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; ++i) cin >> A[i];
int Max = 0, idx = -1;
for (int i = 2; i <= 1000; ++i) {
int cnt = 0;
for (int j = 0; j < N; ++j)
if (A[j] % i == 0) cnt++;
if (Max < cnt) Max = cnt, idx = i;
}
cout << idx << '\n';
return 0;
}

Problem C - To 3

利用一个数能被 \(3\) 整除当且仅当其各位之和能被 \(3\) 整除。

  • 如果本身能被 \(3\) 整除,则不需要删除。
  • 如果被 \(3\) 除余 \(1\),则首先看是否能删去 \(1\) 个 \(1\),然后看是否能删去 \(2\) 个 \(2\)。
  • 如果被 \(3\) 除余 \(1\),则首先看是否能删去 \(1\) 个 \(2\),然后看是否能删去 \(2\) 个 \(1\)。

C++ 代码

int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
string s;
cin >> s;
int cnt[3] = {0};
for (int i = 0; i < s.length(); ++i) cnt[(s[i] - '0') % 3]++;
int cur = (cnt[1] + 2 * cnt[2]) % 3;
int k = cnt[0] + cnt[1] + cnt[2];
int res;
if (!cur) res = 0;
else if (cur == 1) {
if (cnt[1])
if (k == 1) res = -1;
else
res = 1;
else {
if (k == 2) res = -1;
else
res = 2;
}
} else {
if (cnt[2]) {
if (k == 1) res = -1;
else
res = 1;
} else {
if (k == 2) res = -1;
else
res = 2;
}
}
cout << res << "\n";
return 0;
}

Python 代码

s = input()
n = int(s)
if n % 3 == 0:
print(0)
else:
a = list(map(int, list(s)))
c = [0] * 3
for i in a:
c[i % 3] += 1
if c[n % 3] >= 1 and len(a) > 1:
print(1)
elif c[3 - n % 3] >= 2 and len(a) > 2:
print(2)
else:
print(-1)

Problem D - Wandering

记录最远位置 \(ans\),当前位置 \(pos\),前缀和 \(sum\),以及前缀和的最大值 \(hi\)。

在每一轮中,首先更新前缀和,然后更新前缀和的最大值,本轮能达到的最大值显然是 \(pos+hi\),用其更新 \(ans\),再用 \(pos+sum\) 更新 \(pos\)。

时间复杂度 \(\mathcal{O}(N)\)。

using ll = long long;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
ll a, sum = 0, hi = 0, ans = 0, pos = 0;
for (int i = 0; i < n; ++i) {
cin >> a;
sum += a;
hi = max(hi, sum);
ans = max(ans, pos + hi);
pos += sum;
}
cout << ans << "\n";
return 0;
}

Problem E - Akari

将所有灯和墙都放到矩形中,然后逐行从左到右扫描一遍,再从右到左扫描一遍;逐列从上到下扫描一遍,再从下到上扫描一遍。最后统计亮着的格子即可。

时间复杂度 \(\mathcal{O}(HW)\)。

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int e[1510][1510];
bool vis[1510][1510];
int cnt = 0;
struct node {
int x, y;
};
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int h, w, n, m;
cin >> h >> w >> n >> m;
vector<node> bulbs(n);
for (int i = 0; i < n; ++i) {
int x, y;
cin >> x >> y, e[x][y] = 1; // bulb
bulbs[i].x = x, bulbs[i].y = y;
}
for (int i = 0; i < m; ++i) {
int x, y;
cin >> x >> y, e[x][y] = 2; // block
}
for (int i = 0; i < n; ++i) {
int x = bulbs[i].x, y = bulbs[i].y;
if (vis[x][y] == false) {
cnt++, vis[x][y] = true;
}
while ((e[x][y] == 0 || (x == bulbs[i].x and y == bulbs[i].y)) &&
x > 0 && x <= h && y > 0 && y <= w) {
if (vis[x][y] == false) cnt++, vis[x][y] = true;
x++;
}
x = bulbs[i].x, y = bulbs[i].y;
while ((e[x][y] == 0 || (x == bulbs[i].x and y == bulbs[i].y)) &&
x > 0 && x <= h && y > 0 && y <= w) {
if (vis[x][y] == false) cnt++, vis[x][y] = true;
x--;
}
x = bulbs[i].x, y = bulbs[i].y;
while ((e[x][y] == 0 || (x == bulbs[i].x and y == bulbs[i].y)) &&
x > 0 && x <= h && y > 0 && y <= w) {
if (vis[x][y] == false) cnt++, vis[x][y] = true;
y--;
}
x = bulbs[i].x, y = bulbs[i].y;
while ((e[x][y] == 0 || (x == bulbs[i].x and y == bulbs[i].y)) &&
x > 0 && x <= h && y > 0 && y <= w) {
if (vis[x][y] == false) cnt++, vis[x][y] = true;
y++;
}
}
cout << cnt << '\n';
return 0;
}

Problem F - Valid payments

dalao 题解,Orz...

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 52;
ll a[N], mx[N], xx[N], dp[N][2];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int n;
ll x, t;
cin >> n >> x;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i < n; ++i) mx[i] = a[i + 1] / a[i];
t = x;
for (int i = n; i; --i) {
xx[i] = t / a[i];
t %= a[i];
}
dp[1][0] = 1;
if (xx[1]) dp[1][1] = 1;
for (int i = 1; i < n; ++i) {
dp[i + 1][0] = dp[i][0];
if (xx[i + 1]) dp[i + 1][1] = dp[i][0];
dp[i + 1][1] += dp[i][1];
if (xx[i + 1] + 1 != mx[i + 1]) dp[i + 1][0] += dp[i][1];
}
cout << dp[n][0] << '\n';
return 0;
}

这道题,我们实际上就是要求出满足

\[\sum k_ia_i=x
\]

并且满足

\[∀k_i ,∣k_ia_i∣<a_{i+1}
\]

的整数元组 \(\{k_i\}\)的种数。

我们不妨从小到大进行选择。容易看到,我们其实只需要记录当前每一个可能达到的总数以及对应的方法数,而不需要记录对应的具体方案。因为\(a_{i+1}\)总是\(a_i\)的倍数,所以在选择完\(a_i\)的系数k_iki后,我们需要保证此时的总数能够被\(a_{i+1}\)整除。同时,因为\(|k_ia_i| < a_{i+1}\)的限制,因此,对于每一个原有的状态,我们实际上只能有两种选择。

我们以\(\{x,1\}\)作为初始状态开始递推。看起来,状态数会以指数规模增长,但实际上,任意时刻,我们最多同时保留两个状态,因此总时间复杂度为 \(\mathcal{O}(N)\)。

using ll = long long;
int main() {
int n;
ll x;
cin >> n >> x;
vector<ll> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
unordered_map<ll, ll> v;
v[x] = 1;
ll ans = 0;
for (int i = 0; i < n; ++i) {
unordered_map<ll, ll> nv;
for (auto [c, f] : v) {
if (i + 1 < n) {
ll rem = c % a[i + 1];
nv[c - rem] += f;
if (rem > 0) nv[c + a[i + 1] - rem] += f;
} else if (c % a[i] == 0)
nv[0] += f;
}
v = move(nv);
}
cout << v[0];
}

AtCoder Beginner Contest 182 Person Editorial的更多相关文章

  1. AtCoder Beginner Contest 182 D - Wandering (前缀和)

    题意:在\(x\)轴上,你刚开始在\(0\)的位置,第\(i\)次操作需要走\(A_1,...,A_i\)个单位,如果\(A_i\)为正向右走,否则向左走,求你所能走到的最大坐标. 题解:我们一步一步 ...

  2. AtCoder Beginner Contest 182 F

    F - Valid payments 简化题意:有\(n\)种面值的货币,保证\(a[1]=1,且a[i+1]是a[i]的倍数\). 有一个价格为\(x\)元的商品,付款\(y\)元,找零\(y-x\ ...

  3. AtCoder Beginner Contest 100 2018/06/16

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

  4. AtCoder Beginner Contest 052

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

  5. AtCoder Beginner Contest 053 ABCD题

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

  6. AtCoder Beginner Contest 136

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

  7. AtCoder Beginner Contest 137 F

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

  8. AtCoder Beginner Contest 076

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

  9. AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】

    AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...

  10. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

随机推荐

  1. mysql 安装避坑指南 ,mysql 安装后不能启动, mysql 指定版本安装,mysql 5.7.39版本安装,mysql 5.7.36版本安装

    mysql 安装后不能启动,报错如下:请参照本说明第7条的办法解决.mysqld.service: Control process exited, code=exited status=1Please ...

  2. 【Javaweb】jsp | 简单学习【笔记保存】

    什么是jsp,它有什么用? jsp的全称是java server pages.Java的服务器界面. jsp的主要作用是代替Servlet程序回传html页面的数据 因为Servlet程序回传html ...

  3. Net 高级调试之十一:托管堆布局架构和对象分配机制

    一.简介 今天是<Net 高级调试>的第十一篇文章,这篇文章来的有点晚,因为,最近比较忙,就没时间写文章了.现在终于有点时间,继续开始我们这个系列.这篇文章我们主要介绍托管堆的架构,对象的 ...

  4. 【UniApp】-uni-app-全局数据和局部数据

    前言 好,经过上个章节的介绍完毕之后,了解了一下 uni-app-全局样式和局部样式 那么了解完了全局样式和局部样式之后,这篇文章我再来给大家介绍一下 UniApp 中全局数据和局部数据 搭建演示环境 ...

  5. 使用 GPT4V+AI Agent 做自动 UI 测试的探索

    一.背景 从 Web 诞生之日起,UI 自动化就成了测试的难点,到现在近 30 年,一直没有有效的手段解决Web UI测试的问题,尽管发展了很多的 webdriver 驱动,图片 diff 驱动的工具 ...

  6. 数字孪生融合GIS系统能够为物流行业提供什么解决方案?

    全球贸易和电子商务的不断发展,让物流行业面临着越来越多的挑战.其中,提高运输效率.降低成本.优化供应链和增强可持续性等问题成为业界关注的焦点.在这个数字化时代,数字孪生和GIS系统的融合为物流行业带来 ...

  7. auto{x}与auto(x)---一位中国小伙为cppreference作出的贡献

      C++作为一门静态类型语言,是需要程序员声明变量类型的.然而来到了C++11,auto的诞生使得变量声明变得及为方便,尤其是对于比较长的模板类型,auto一定程度上为代码编写者减轻了负担.到了C+ ...

  8. postman——下载与安装

    一.postman是什么? 那么,Postman是个什么东东呢?Postman的官网上这么介绍它:"Modern software is built on APIs,Postman help ...

  9. [研究]SpringBoot-MybatisPlus-Dynamic(多数据源)

    SpringBoot-MybatisPlus-Dynamic(多数据源) 前言 ​ 基于工作上班累死了...打开自己电脑 不知道干些啥 就康康 PL 网站康康 更新了啥 ​ 咦~~~还挺多 看到了多数 ...

  10. 首次引入大模型!Bert-vits2-Extra中文特化版40秒素材复刻巫师3叶奈法

    Bert-vits2项目又更新了,更新了一个新的分支:中文特化,所谓中文特化,即针对中文音色的特殊优化版本,纯中文底模效果百尺竿头更进一步,同时首次引入了大模型,使用国产IDEA-CCNL/Erlan ...