比赛链接:https://atcoder.jp/contests/abc165/tasks

A - We Love Golf

题意

区间 $[a, b]$ 中是否存在 $k$ 的倍数。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
int k, a, b; cin >> k >> a >> b;
for (int i = a; i <= b; i++) {
if (i % k == 0) {
cout << "OK";
return 0;
}
}
cout << "NG";
}

B - 1%

题意

一开始在银行存有 $100$ 元,年利率为 $\lfloor \frac{n}{100} \rfloor$,问多少年后存款不少于 $x$ 元。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
long long x; cin >> x;
long long sum = 100;
for (int i = 1; i < INT_MAX; i++) {
sum += sum / 100;
if (sum >= x) {
cout << i << "\n";
return 0;
}
}
}

C - Many Requirements

题意

构造一个长为 $n$ 的数组 $A$,其中 $1 ≤ A_1 ≤ A_2 ≤ ... ≤ A_n ≤ m$。

另有数组 $a,b,c,d$,如果 $A_{b_i} - A_{a_i} = c_i$,则该数组的价值加上 $d_i$ ,求能构造出的数组的最大价值。

题解

枚举所有情况即可。

代码

#include <bits/stdc++.h>
using namespace std; int n, m, q;
int a[50], b[50], c[50], d[50];
int A[10], ans; void dfs(int dep, int pre) {
if (dep == n) {
int sum = 0;
for (int i = 0; i < q; i++)
if (A[b[i]] - A[a[i]] == c[i]) sum += d[i];
ans = max(ans, sum);
return;
}
for (int i = pre; i <= m; i++) {
A[dep] = i;
dfs(dep + 1, i);
}
} int main() {
cin >> n >> m >> q;
for (int i = 0; i < q; i++) {
cin >> a[i] >> b[i] >> c[i] >> d[i];
--a[i], --b[i];
}
dfs(0, 1);
cout << ans << "\n";
}

D - Floor Function

题意

求 $max( \lfloor \frac{Ax}{B}  \rfloor - A \lfloor \frac{x}{B} \rfloor )$ 。

题解

设 $x = cB + d\ (0≤c,\ 0≤d<B)$

$\ \ \ \ \lfloor \frac{Ax}{B}  \rfloor - A \lfloor \frac{x}{B} \rfloor$

$=\lfloor \frac{A(cB+d)}{B} \rfloor - A \lfloor \frac{cB+d}{B} \rfloor$

$=Ac + \lfloor \frac{Ad}{B} \rfloor - Ac - A \lfloor \frac{d}{B} \rfloor$

$=\lfloor \frac{Ad}{B} \rfloor - A \lfloor \frac{d}{B} \rfloor$

$=\lfloor \frac{Ad}{B} \rfloor$

即求 $max(\lfloor \frac{Ad}{B} \rfloor)$,取 $d$ 的最大值即可。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, n; cin >> a >> b >> n;
cout << a * min(b - 1, n) / b << "\n";
}

E - Rotation Matching

题意

有 $n$ 个选手,$m$ 个比赛场地,为每 $m$ 个比赛场地指定一对选手的编号(一个编号只能出现在一个比赛场地),来保证在之后的 $n$ 轮比赛中,所有选手不会与同一选手比赛两次,每轮比赛后所有选手编号加 $1$,编号 $n+1$ 的变为 $1$。

题解

一个选手最多的情况是要与 $m$ 个人一人比一次,所以 $m$ 对编号应取 $m$ 个不同的间隔。

即在 $[1, n]$ 中取 $m$ 对数,每对数间隔不同的长度。

代码

待填

F - LIS on Tree

题意

一棵有 $n$ 个结点的树,每个结点有一个值,输出每个从根节点 $1$ 到其他点最短路的值序列中 $LIS$ 的长度。

题解

维护一个最长单调序列即可。

代码一

#include <bits/stdc++.h>
using namespace std; const int M = 2e5 + 100;
vector<int> e[M];
int a[M], ans[M];
int b[M], len; void dfs(int u, int pre) {
int id = lower_bound(b, b + len, a[u]) - b;
int del = -1;
if (id == len) ++len;
else del = b[id];
b[id] = a[u];
ans[u] = len;
for (auto v : e[u]) {
if (v != pre) {
dfs(v, u);
}
}
if (del == -1) --len;
else b[id] = del;
} int main() {
int n; cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n - 1; i++) {
int u, v; cin >> u >> v;
--u, --v;
e[u].push_back(v);
e[v].push_back(u);
}
dfs(0, -1);
for (int i = 0; i < n; i++) cout << ans[i] << "\n";
}

代码二

再贴一下用 $set$ 的做法,需要注意一些语句的前后顺序。

#include <bits/stdc++.h>
using namespace std; const int M = 2e5 + 100;
vector<int> e[M];
int a[M], ans[M];
set<int> st; void dfs(int u, int pre) {
auto it = st.lower_bound(a[u]);
int del = -1;
if (it != st.end()) {
del = *it;
st.erase(it);
}
st.insert(a[u]);
ans[u] = st.size();
for (auto v : e[u]) {
if (v != pre) {
dfs(v, u);
}
}
st.erase(a[u]);
if (del != -1) st.insert(del);
} int main() {
int n; cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n - 1; i++) {
int u, v; cin >> u >> v;
--u, --v;
e[u].push_back(v);
e[v].push_back(u);
}
dfs(0, -1);
for (int i = 0; i < n; i++) cout << ans[i] << "\n";
}

AtCoder Beginner Contest 165的更多相关文章

  1. AtCoder Beginner Contest 100 2018/06/16

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

  2. AtCoder Beginner Contest 052

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

  3. AtCoder Beginner Contest 053 ABCD题

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

  4. AtCoder Beginner Contest 136

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

  5. AtCoder Beginner Contest 137 F

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

  6. AtCoder Beginner Contest 076

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

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

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

  8. AtCoder Beginner Contest 064 D - Insertion

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

  9. AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle【暴力】

    AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle 我要崩溃,当时还以为是需要什么离散化的,原来是暴力,特么五层循环....我自己写怎么都 ...

随机推荐

  1. Spring Boot Security 国际化 多语言 i18n 趟过巨坑

    网上很多的spring boot国际化的文章都是正常情况下的使用方法 如果你像我一样用了Spring Security 那么在多语言的时候可能就会遇到一个深渊 Spring Security里面的异常 ...

  2. LeetCode222 判断是否为完全二叉树并求节点个数

    给出一个完全二叉树,求出该树的节点个数. 说明: 完全二叉树的定义如下:在完全二叉树中,除了最底层节点可能没填满外,其余每层节点数都达到最大值,并且最下面一层的节点都集中在该层最左边的若干位置.若最底 ...

  3. Writing in the science: Introducion

    1.what makes a good writing? 2.what makes a good writer? 1) have something to say 2) logical thinkin ...

  4. 【MySQL】使用WHERE子句 - 过滤数据

    第6章 过滤数据 文章目录 第6章 过滤数据 1.使用WHERE子句 2.WHERE子句操作符 2.1.检查单个值 2.2.不匹配检查 2.3.范围值检查 2.4.空值检查 3.小结 简单记录 - M ...

  5. oracle分区表分区栏位NULL值测试

    实验在分区栏位为NULL时,分区表的反应 1.创建普通的分区表 CREATE TABLE MONKEY.TEST_PART_NULL_NORMAL ( ID NUMBER, ADD_DATE DATE ...

  6. Py集合,字符串的格式化,函数,便利

    可变与不可变 不可变指的是:重新赋值时,内存中的id值会变得 其中有:字符串,数字,元组 name="sb" v=id(name) print(v) name ="ale ...

  7. 3、wait和waitpid

    1. 函数介绍 wait函数:调用该函数使进程阻塞,直到任意一个子进程结束,或者该进程接收到了一个信号为止,如果该进程没有子进程或该进程的子进程已经结束,wait函数立即返回. waitpid函数:与 ...

  8. 《UML与设计原则》--第四小组

    关于设计模式与原则 一.设计模式简介 设计模式描述了软件设计过程中某一类常见问题的一般性的解决方案.而面向对象设计模式描述了面向对象设计过程中特定场景下.类与相互通信的对象之间常见的组织关系. 二.G ...

  9. Mybatis总结(一)

    Mybatis总结(一) 一.Mybatis启动流程(代码层面) 关于config.xml <?xml version="1.0" encoding="UTF-8& ...

  10. 在这个应用中,我使用了 MQ 来处理异步流程、Redis 缓存热点数据、MySQL 持久化数据,还有就是在系统中调用另外一个业务系统的接口,对我的应用来说这些都是属于 RPC 调用,而 MQ、MySQL 持久化的数据也会存在于一个分布式文件系统中,他们之间的调用也是需要用 RPC 来完成数据交互的。

    在这个应用中,我使用了 MQ 来处理异步流程.Redis 缓存热点数据.MySQL 持久化数据,还有就是在系统中调用另外一个业务系统的接口,对我的应用来说这些都是属于 RPC 调用,而 MQ.MySQ ...