写在前边

链接:Codeforces Round #704 (Div. 2)

D就不补了,大fst场。

A. Three swimmers

链接:A题链接

题目大意:

给定三个游泳者的到达岸边的周期,\(a,b,c\),而你到达岸边的时间为\(p\),现在问你到达岸边后最少需要多少时间能遇到一名游泳者。

思路

老套路题了,公式:

\[res = min(\lceil \cfrac{p}{a} \rceil * a, \lceil \cfrac{p}{b} \rceil * b, \lceil \cfrac{p}{c} \rceil * c) - p
\]

注意,写代码的时候\((p + a - 1) / a * a\) 与\(a * (p + a - 1) / a\)获得的结果也不一样,前一种正确。

代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <unordered_map> using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n' typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; void solve() {
LL p, a, b, c;
cin >> p >> a >> b >> c;
LL a1, b1, c1;
a = (p + a - 1) / a * a;
b = (p + b - 1) / b * b;
c = (p + c - 1) / c * c; cout << min(a, min(b, c)) - p << endl;
} int main()
{
//ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
solve();
} return 0;
}

B. Card Deck

链接:B题链接

题目大意:

一副扑克盘,从上往下拿,截止点作为新牌的起点,会形成一种新的顺序,使得这种顺序权值最大,计算权值公式:

\[\sum\limits_{i = 1}^n n^{n - i} * p_i
\]

思路

把公式展开后就得出让新的牌须变成字典序最大即可,那么我们就每一次以剩余的最大数作为截止点拿牌,形成新的顺序,一开始就想到这种方法了,但是复杂度想成了\(O(n^2)\)没敢做,于是看题解后,做的也是这种方法,于是想了一下复杂度并不是\(O(n^2)\),最坏是是\(O(n + n)\)

代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
#include <set> //#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline") using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n' typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; const int Mod = 10000007; LL gcd(LL a, LL b) {
return b ? gcd(b, a % b) : a;
} const int N = 1e5 + 10;
int a[N]; void solve() {
int n;
scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); set<int> st;
vector<int> rem;
for (int i = 1; i <= n; i++) st.insert(i); int maxn = n;
for (int i = n; i >= 1; i--) {
rem.push_back(a[i]);
st.erase(a[i]);
if (a[i] == maxn) {
reverse(rem.begin(), rem.end());
for (auto &it : rem) cout << it << " ";
rem.clear();
if (st.size()) maxn = *(--st.end());
}
}
cout << endl;
} int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}

C. Maximum width

链接:C题链接

题目大意:

给定一个长度分别为\(n,m\)的字符串\(s,t\),同时可以得到一个序列\(p\),\(1 \leq p_1 \leq p_2 \leq p_3 \leq ... \leq n\),使得\(s_{p_i} = t_i\)对于所有的\(s[1, m]\),让我们构造以\(p\)得到一个\(\max\limits_{1 \leq i \leq m} (p_{i + 1} - p_i)\)。

思路

每次做这种题都会让坐标烦,这道题仔细抠一下题意就是在\(s\)中找到一个\(t\),并使得\(t\)在\(s\)中相邻两个字母的坐标差最大,那么可以分别从前边可后边维护两个数组\(f,g\),\(f_i\)表示\(t_i\)在s中最左侧位置下标,\(g_i\)就表示\(t_i\)在\(s\)中最右侧位置的下边,那么答案就是\(\max\limits_{1 \leq i \leq {m - 1}} (g_{i + 1} - f_i)\)

代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <unordered_map> using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n' typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; const int N = 2e5 + 10;
char s[N], t[N];
int f[N], g[N]; void solve() {
int n, m;
scanf("%d%d", &n, &m);
scanf("%s", s + 1);
scanf("%s", t + 1); int cnt = 1;
for (int i = 1; i <= m; i++) {
while (s[cnt] != t[i]) cnt++;
f[i] = cnt;
cnt++;
} cnt = n;
for (int i = m; i >= 1; i--) {
while (s[cnt] != t[i]) cnt--;
g[i] = cnt;
cnt--;
} int res = 0;
for (int i = 1; i <= m - 1; i++) res = max(res, g[i + 1] - f[i]);
printf("%d\n", res);
} int main()
{
solve();
return 0;
}

Codeforces Round #704 (Div. 2) A~C题解的更多相关文章

  1. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  2. Codeforces Round #198 (Div. 2)A,B题解

    Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...

  3. Codeforces Round #672 (Div. 2) A - C1题解

    [Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...

  4. Codeforces Round #614 (Div. 2) A-E简要题解

    链接:https://codeforces.com/contest/1293 A. ConneR and the A.R.C. Markland-N 题意:略 思路:上下枚举1000次扫一遍,比较一下 ...

  5. Codeforces Round #610 (Div. 2) A-E简要题解

    contest链接: https://codeforces.com/contest/1282 A. Temporarily unavailable 题意: 给一个区间L,R通有网络,有个点x,在x+r ...

  6. Codeforces Round #611 (Div. 3) A-F简要题解

    contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...

  7. Codeforces Round #499 (Div. 2) D. Rocket题解

    题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...

  8. Codeforces Round #499 (Div. 2) C Fly题解

    题目 http://codeforces.com/contest/1011/problem/C Natasha is going to fly on a rocket to Mars and retu ...

  9. Codeforces Round #198 (Div. 2)C,D题解

    接着是C,D的题解 C. Tourist Problem Iahub is a big fan of tourists. He wants to become a tourist himself, s ...

  10. Codeforces Round #579 (Div. 3) 套题 题解

    A. Circle of Students      题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...

随机推荐

  1. vlan与单臂路由

    vlan 1,什么是vlan vlan叫做虚拟局域网 (VLAN, Virtual LAN) 虚拟局域网(VLAN)是一组逻辑上的设备和用户,这些设备和用户并不受物理位置的限制,可以根据功能.部门及应 ...

  2. 洛谷 P1336 最佳课题选择 题解

    P1336 最佳课题选择 题解 状态:考虑\(f_{i,j}\)表示前\(i\)种论文里面,一共写了\(j\)篇,的最少花费时间. 转移策略:我们一次考虑每一种论文写多少篇.假设写\(k\)篇,\(k ...

  3. [nginx]防范空主机头

    空主机头防范主要是防止别人恶意将域名解析到服务器IP上. 配置示例 方式一,增加vhost # http的空主机头防范 server { listen 80 default; server_name ...

  4. [nginx]proxy_cache缓存系统

    前言 proxy_cache是nginx内置的一个缓存系统,可实现减小后端负载的作用. 常用参数说明 参数 说明 proxy_cache_path 缓存文件路径.level表示目录层级,1:2表示两个 ...

  5. 部署安装kafka集群

    准备 zookeeper节点: 172.50.13.103 172.50.13.104 172.50.13.105 kafka版本: 2.13-2.7.0 安装步骤 部署安装zookeeper集群.参 ...

  6. 使用LabVIEW 实现物体识别、图像分割、文字识别、人脸识别等深度视觉

    前言 哈喽,各位朋友们,这里是virobotics(仪酷智能),这两天有朋友私信问之前给大家介绍的工具包都可以实现什么功能,最新的一些模型能否使用工具包加载,今天就给大家介绍一下博主目前使用工具包已经 ...

  7. JDK中动态库加载路径问题,一文讲清

    前言 本周协助测试同事对一套测试环境进行扩容,我们扩容很原始,就是新申请一台机器,直接把jdk.resin容器(一款servlet容器).容器中web应用所在的目录,全拷贝到新机器上,servlet容 ...

  8. 在Jupyter中使用AI写代码,如有神助,太惊艳了

    昨晚看到一个可以在JupyterLab中使用的AI代码辅助工具jupyter-ai,它的交互确实非常棒,可以直接聊天,也可以就笔记中的代码提问,最出彩的是生成笔记功能,还是蛮惊艳的. 这里就极简介绍一 ...

  9. Webpack性能优化 SplitChunksPlugin的使用详解

    使用前景 在vue.react等使用webpack为项目打包工具的前端项目,在开发过程中,随着项目功能的逐渐增加,项目整体体积的不断增加,打包的时长和打包后部署的项目体积也在不停的增长,这样可能会导致 ...

  10. 其它——Siege压力测试工具使用

    文章目录 Siege压力测试工具使用 一 Siege介绍 二 windows 下使用 三 mac和linux使用 四 使用 五 参数详解 六 结果详解 七 修改系统的文件描述符限制 Siege压力测试 ...