A - Difference Max

区间左端减去区间右端

int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << b - c << endl;
return 0;
}

B - Round Down

一开始想错了,应该String读入,然后find('.')的位置即可,如果没有说明原来就是整数

int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
string s;
cin >> s;
int idx = s.find('.');
if (idx == -1) cout << s;
else
for (int i = 0; i < idx; ++i) cout << s[i];
return 0;
}

C - Doubled

\(N \le 10^{12}\) 过大,所以不可能直接通过整数解决。

利用 字符串 的连接性质转化为 long long 进行判断即可,尽管稍微仍比较耗时但能够 AC

using ll = long long;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
ll n, x = 0;
cin >> n;
while (stoll(to_string(x) + to_string(x)) <= n) x++;
cout << x - 1 << "\n"; // 把 0 算进去了,所以要减一
return 0;
}

**D - Hanjo **

题意:在 HW 的面积里放置 A个 \(2\times1\) 长方块榻榻米,B个 \(1\times1\) 方形榻榻米。请问有多少种放置方法。

根据官方的题解,对于这个 \(HW \le 16\) 是约束很小的情况,所以我们可以使用 DFS 进行完全爆搜。

从左上角的格子开始,尝试放置一个方形榻榻米垫,个长方形榻榻米垫,在左侧或下方突出;然后我们可以穷尽地搜索所有的覆盖方式。

现在让我们估计一下时间复杂度。

我们有左上角单元格和榻榻米方向的选择,所以我们有答案的上界 \(2^A(\begin{smallmatrix} HW\\A \end{smallmatrix})\)。

由于 \(2^A(\begin{smallmatrix} HW\\A \end{smallmatrix})\) 的最大值为 \(5 \times10^7\),所以速度足够快。

事实上,最大答案是3388,所以它的工作速度比估计的要快得多。

int H, W, A, B, ans = 0;
void dfs(int i, int bit, int A, int B) {
if (i == H * W) return (void)ans++;
if (bit & 1 << i) return dfs(i + 1, bit, A, B);
if (B) dfs(i + 1, bit | 1 << i, A, B - 1);
if (A) {
if (i % W != W - 1 && ~bit & 1 << (i + 1))
dfs(i + 1, bit | 1 << i | 1 << (i + 1), A - 1, B);
if (i + W < H * W) dfs(i + 1, bit | 1 << i | 1 << (i + W), A - 1, B);
}
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
cin >> H >> W >> A >> B;
dfs(0, 0, A, B);
cout << ans << "\n";
return 0;
}

E - Filters

https://atcoder.jp/contests/abc196/editorial/953

#include <algorithm>
#include <iostream>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = numeric_limits<ll>::max() / 4;
void chmin(ll& a, ll b) { return (void)(a > b ? a = b : a = a); }
void chmax(ll& a, ll b) { return (void)(a < b ? a = b : a = a); }
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
ll N;
cin >> N;
ll low = -INF, high = INF, add = 0;
for (ll i = 0; i < N; ++i) {
ll A, T;
cin >> A >> T;
if (T == 1) low += A, high += A, add += A;
else if (T == 2)
chmax(low, A), chmax(high, A);
else
chmin(low, A), chmin(high, A);
}
ll Q, x;
cin >> Q;
while (Q--) {
cin >> x;
// clamp 用来判断一个值是否“夹”在另外一对值之间,如果在区间内则返回
// x,如果大于左区间则返回左区间,不然返回右区间 // cout << clamp(x + add, low, high) << '\n';
cout << min(high, max(low, x + add)) << "\n";
}
return 0;
}

AtCoder Beginner Contest 196 个人题解的更多相关文章

  1. KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解

    KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...

  2. AtCoder Beginner Contest 089完整题解

    A - Grouping 2 Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement There a ...

  3. 2018.09.08 AtCoder Beginner Contest 109简要题解

    比赛传送门 水题大赛? 全是水题啊!!! T1 ABC333 就是判断是不是两个数都是奇数就行了. 代码: #include<bits/stdc++.h> using namespace ...

  4. Atcoder Beginner Contest 138 简要题解

    D - Ki 题意:给一棵有根树,节点1为根,有$Q$次操作,每次操作将一个节点及其子树的所有节点的权值加上一个值,问最后每个节点的权值. 思路:dfs序再差分一下就行了. #include < ...

  5. AtCoder Beginner Contest 154 题解

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

  6. AtCoder Beginner Contest 153 题解

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

  7. AtCoder Beginner Contest 177 题解

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

  8. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

  9. AtCoder Beginner Contest 173 题解

    AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...

  10. AtCoder Beginner Contest 172 题解

    AtCoder Beginner Contest 172 题解 目录 AtCoder Beginner Contest 172 题解 A - Calc B - Minor Change C - Tsu ...

随机推荐

  1. EMCC13.5+Oracle19.13+Redhat8 In Silent Mode

    问题描述:使用静默的方式来安装emcc13.5+Oracle19.13,准备好19c的oracle环境,一开始用21c的库+emcc13.5的安装检查一直过不去,但是19c是没有问题的,具体问题会在下 ...

  2. 这下对阿里java这几条规范有更深理解了

    背景 阿里java开发规范是阿里巴巴总结多年来的最佳编程实践,其中每一条规范都经过仔细打磨或踩坑而来,目的是为社区提供一份最佳编程规范,提升代码质量,减少bug. 这基本也是java业界都认可的开发规 ...

  3. FastJson、Jackson、Gson进行Java对象转换Json

    - Java对象转换Json的细节处理前言Java对象在转json的时候,如果对象里面有属性值为null的话,那么在json序列化的时候要不要序列出来呢?对比以下json转换方式一.fastJson1 ...

  4. 在WPF应用中使用GongSolutions.WPF.DragDrop实现列表集合控件的拖动处理

    WPF应用中,控件本身也可以通过实现事件代码实现拖动的处理,不过如果我们使用GongSolutions.WPF.DragDrop来处理,事情会变得更加简单轻松,它支持很多控件的拖动处理,如ListBo ...

  5. Tensorflow2.0使用Resnet18进行数据训练

    在今年的3月7号,谷歌在 Tensorflow Developer Summit 2019 大会上发布 TensorFlow 2.0 Alpha 版,随后又发布了Beta版本. Resnet18结构 ...

  6. SpringBoot整合Filter过滤器

    话不多说,直接上核心代码 1.先创建一个Filter类 package com.qbb.reggie.filter; import com.alibaba.fastjson.JSON; import ...

  7. 【低代码】低代码平台协同&敏捷场景下的并行开发解决方案探索

    低代码开发平台的出现,大大地提高的产品交付效率,但是在协同开发.敏捷迭代的场景下,也暴露出了一些问题. 例如: 多人同时对项目进行修改,相互影响甚至修改内容被互相覆盖: 同一项目下多个需求同步开发,但 ...

  8. libgdx摄像头的移动

    要知道,做一个游戏,摄像头是必不可少的.接下来,我将讲解libgdx里面摄像头的移动 2d摄像头OrthographicCamera也叫做正交相机 结果展示: 按上下左右是可以移动的 Orthogra ...

  9. 【分享】推荐一个非常好用的redis远程连接工具

    推荐一个非常好用的redis远程连接工具 蓝奏云地址 https://wwsi.lanzoum.com/ig7xZ0xspf0h 密码:4vnz 二维码:

  10. 面试官:请说一下Mysql事务实现原理

    在日常工作中,数据库是我们必须使用的,其中使用最多的也是大部分中小公司的选择是Mysql,跳槽面试中也是必问的,今天我们就说一下Mysql事务 MySQL中的事务实现原理主要涉及以下几个方面: ACI ...