Codeforces Edu Round 57 A-D
A. Find Divisible
符合条件的区间一定可以选择\(l, l * 2\)。
证明\(l * 2 <= r\)
假设存在一组解,\(x, x * d (l <= x <= r, 2 <=d )\)。
因为必定满足条件则:\(l * 2 <= l * d <= x * d <= r\)。
#include <cstdio>
#include <iostream>
using namespace std;
int main(){
int T; scanf("%d", &T);
while(T--){
int l, r; scanf("%d%d", &l, &r);
printf("%d %d\n", l, l * 2);
}
return 0;
}
B. Substring Removal
扫描字符串的前缀和后缀:
- 若所有字母一样,方案数为所有子串\((1 + n) * n / 2\)
- 前缀字母与后缀字母一样,则要么留下前缀,要么留后缀,还有就是都去掉。
- 否则,则两者可以都选,独立事件可以相乘。
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
const int N = 200010, MOD = 998244353;
int n;
char s[N];
int main(){
scanf("%d%s", &n, s + 1);
int l = 1, r = n;
while(s[l] == s[l + 1]) l++;
while(s[r] == s[r - 1]) r--;
if(l == n && r == 1) printf("%lld\n", ((LL)(1 + n) * n / 2) % MOD);
else if(s[l] == s[r]) printf("%lld\n", ((LL)(l + 1) * (n - r + 2)) % MOD);
else printf("%d\n", (l + (n - r + 1) + 1) % MOD);
return 0;
}
C. Polygon for the Angle
一个圆周角、圆心角定理的运用…发现当\(n = 180\) 的时候,所有\(deg < 179\) 都可以表示出来,\(n = 360\)时,所有度数均可满足,于是就可以枚举惹...
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const int N = 190;
int a[N * 2];
int main(){
for(int i = 3; i <= 360; i++){
for(int j = 1; j <= i - 2; j++){
if(180 * j % i == 0 && (!a[180 * j / i]))
a[180 * j / i] = i;
}
}
int T; scanf("%d", &T);
while(T--){
int deg; scanf("%d", °);
printf("%d\n", a[deg]);
}
return 0;
}
D. Easy Problem
\(f[i][j]\)表示前\(i\)个字符 清理到\(hard\) -> 前$ j$ 位的最小花费
每次遇到一个\(hard\)中字符,考虑可以让前 j- 1位不存在,也可以保持之前的状态,删除这个字符。
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
const int N = 100010;
typedef long long LL;
char s[N];
int n, a[N];
LL f[N][4];
//f[i][j] 前i个字符 清理到"hard" -> j 位
int main(){
memset(f, 0x3f, sizeof f);
for(int i = 0; i < 4; i++) f[0][i] = 0;
scanf("%d%s", &n, s + 1);
for(int i = 1; i <= n; i++) scanf("%d", a + i);
for(int i = 1; i <= n; i++){
for(int j = 0; j < 4; j++) f[i][j] = f[i - 1][j];
if(s[i] == 'h') f[i][0] = f[i - 1][0] + a[i];
if(s[i] == 'a') f[i][1] = min(f[i - 1][0], f[i - 1][1] + a[i]);
if(s[i] == 'r') f[i][2] = min(f[i - 1][1], f[i - 1][2] + a[i]);
if(s[i] == 'd') f[i][3] = min(f[i - 1][2], f[i - 1][3] + a[i]);
}
printf("%lld\n", f[n][3]);
return 0;
}
Codeforces Edu Round 57 A-D的更多相关文章
- Codeforces Beta Round #57 (Div. 2)
Codeforces Beta Round #57 (Div. 2) http://codeforces.com/contest/61 A #include<bits/stdc++.h> ...
- Codeforces Educational Round 57
这场出题人好像特别喜欢998244353,每个题里都放一个 A.Find Divisible 考察选手对输入输出的掌握 输出l 2*l即可(为啥你要放这个题,凑字数吗 #include<cstd ...
- Codeforces Beta Round #57 (Div. 2) A,B,C,D,E
A. Ultra-Fast Mathematician time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces Beta Round #57 (Div. 2) E. Enemy is weak
求满足条件的三元组的个数,可以转换求一元组和二元组组成的满足条件的三元组的个数,且对于(x),(y,z),x > y,且x出现的p_x < p_y. x可直接枚举O(n),此时需要往后查询 ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #62 题解【ABCD】
Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #13 C. Sequence (DP)
题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...
- CH Round #57 - Story of the OI Class 凯撒密码
很有意思的一道题目 考场上想的是HASH成一个整数,把末位asicc码值*1,依次乘*10,得到一个整数,然后利用等差性.唯一性快排Nlogn乱搞的 证明如下: 对于明文abcde 密文 bcdef ...
随机推荐
- UNP——第二章,TCP状态,TIME_WAIT
状态可以用 netstat 验证 加粗线为 数据交换. 可以看出,TCP在 建立连接和 关闭连接,耗费资源, 因为UDP只需要两次数据通信即可. 但UDP没有可靠传输,和流量控制. 上面协商的MSS为 ...
- 从 Webpack 到 Snowpack, 编译速度提升十倍以上——TRPG Engine迁移小记
动机 TRPG Engine经过长久以来的迭代,项目已经显得非常臃肿了.数分钟的全量编译, 每次按下保存都会触发一次10s到1m不等的增量编译让我苦不堪言, 庞大的依赖使其每一次编译都会涉及很多文件和 ...
- 这行代码告诉你!为什么你地下城与勇士(DNF)的装备强化老是失败?
模拟地下城与勇士(DNF)的装备强化 tip1: DNF装备强化在+1-+3 不会失败: +4-+7,失败后物品原有强化等级降低1级: +8-+10,失败后掉3级: 10上11或以上就爆了. tip2 ...
- Cypress系列(93)- Cypress.dom 命令详解
如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 作用 与 DOM 元素相关的 helpe ...
- 【VUE】5.路由导航守卫
1. 功能需求 1. 当用户登陆成功后,把得到的token存到Session Storage 2. components -> Form.vue , 对预验证进行校验,如果验证不正确就跳出,如果 ...
- 关于CopyOnWriterArrayList的一些理解
学了cowarraylist之后,有些不明白的地方, 1.我们为什么要用写时复制的策略呢?,这样每次不是都要复制吗,性能不是很低吗?直接在元素组上扩容不好吗?而且读的时候数据一致性也保证不了,如果只是 ...
- LaTeX中的插图
插图代码及注释: 显示效果: 更多命令可以看相关文档,通过在命令行终端输入 texdoc graphicx 命令打开文档.
- mysql GTID主从复制故障后不停机恢复同步流程
GTID实现主从复制数据同步 GTID是一个基于原始mysql服务器生成的一个已经被成功执行的全局事务ID,它由服务器ID以及事务ID组成,这个全局事务ID不仅仅在原始服务器上唯一,在所有主从关系的m ...
- CentOS 7定时执行python脚本
CentOS 7定时执行python脚本 在CentOS下,可以使用crontab进行定时任务的处理. 一.crontab的安装 默认情况下,CentOS 7中已经安装有crontab,如果没有安装, ...
- MySQL 当前时间,今日时间,前日时间 详解
MySQL 获取当前日期及日期格式 获取系统日期: NOW() 格式化日期: DATE_FORMAT(date, format) 注: date:时间字段 format:日期格式 返回系统日期,输出 ...