【cf比赛记录】Educational Codeforces Round 78 (Rated for Div. 2)
A. Shuffle Hashing
题意:加密字符串。可以把字符串的字母打乱后再从前面以及后面接上字符串。问加密后的字符串是否符合加密规则。
题解:字符串的长度很短,直接暴力搜索所有情况
// https://codeforces.com/contest/1278/problem/A
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int T;
char p[102], h[102];
int pnum[30], hnum[30];
int main()
{
scanf("%d", &T);
while(T--){
memset(pnum, 0, sizeof(pnum));
// memset(hnum, 0, sizeof(hnum));
scanf("%s %s", p, h);
int plen = strlen(p); // 原字符串长度
int hlen = strlen(h); // 加密后的长度
for(int i = 0; i < plen; i++){
pnum[p[i] - 'a']++; // 记录原字符串的字母个数
}
bool flag = false;
for(int i = 0; i < hlen; i++){
bool ok = true;
memset(hnum, 0, sizeof(hnum)); // hnum 记录机密后的字符串字母的个数
if(hlen - plen < i || flag) break;
for(int j = 0, k = i; j < plen && k < hlen; j++, k++){
int who = h[k] - 'a';
hnum[h[k] - 'a']++;
if(hnum[who] > pnum[who]) {
ok = false;
break;
}
}
if(ok) flag = true;
}
if(flag) printf("YES\n");
else printf("NO\n");
}
return 0;
}
B. A and B
题意:第 \(i\) 步可以给A或者B加上 \(i\) ,求使得他们相等的最少步数
题解:数学题。先打表 f(i) = (i + 1) * i / 2;(f(1) < 1e9)。然后求 | A - B | ,当 f(x) >= |A - B| 时判断它们的差的奇偶性,如果是偶数则输出 x, 如果是奇数则分情况讨论:如果 x 为奇数,则输出 x+2;否则输出 x+1。
为什么呢?我们先把所有的数都加到较小的那个数(假设这里是a)里,当操作一轮后a的和比b要大,则说明此时需要把一部分a的操作数加到b那边去,其实b+i == a-i。此时 a + f(x) >= b 。 假如当 a + f(x) - b == 2 时,我们只需要把 a 当时的 +1 改为 -1 即可,所以操作数是没有变化的(如果是 == 4 则把 +2 改为 -2,以此类推)。而当 a + f(x) - b == k(k是奇数时), 且 x 此时是奇数时,则 a 加上下一个数的时候是加上一个偶数,偶数加奇数还是奇数,所以还要再操作一次;如果当前操作数是偶数时同理。a + f(x) - b 等价于 f(x) - (b - a) 分别对应 打表的f(i) 与 一开始两数的差。
// https://codeforces.com/contest/1278/problem/B
// Thanks for my gf.
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int T, a, b;
int num[1000006];
int cnt = 1;
void build(){
int x = 1, i = 1;
while(x <= 1000000000){
x = (i + 1) * i / 2;
num[cnt++] = x;
i++;
}
}
int main()
{
build();
scanf("%d", &T);
while(T--){
scanf("%d %d", &a, &b);
int sub = abs(a - b);
if(sub == 0) {
printf("0\n");
continue;
}
// printf("cnt:%d\n", cnt);
for(int i = 1; i <= cnt; i++){
if(num[i] >= sub){
if((num[i]-sub) % 2 == 0) {
printf("%d\n", i);
break;
}
else {
if(i % 2 == 0){
printf("%d\n", i + 1);
}
else printf("%d\n", i + 2);
break;
}
}
}
}
return 0;
}
C. Berry Jam
太难(cai)了我,看了很多题解才弄清楚了操作。下面直接贴博客吧。感谢大佬们的题解。因为代码跟大佬的相似,所以就不贴了
https://www.cnblogs.com/KisekiPurin2019/p/12074593.html
https://www.cnblogs.com/shoulinniao/p/12075697.html
记录菜鸟成长:


【cf比赛记录】Educational Codeforces Round 78 (Rated for Div. 2)的更多相关文章
- Educational Codeforces Round 78 (Rated for Div. 2) C. Berry Jam
链接: https://codeforces.com/contest/1278/problem/C 题意: Karlsson has recently discovered a huge stock ...
- Educational Codeforces Round 78 (Rated for Div. 2)
A题 给出n对串,求s1,是否为s2一段连续子串的重排,串长度只有100,从第一个字符开始枚举,sort之后比较一遍就可以了: char s1[200],s2[200],s3[200]; int ma ...
- Educational Codeforces Round 78 (Rated for Div. 2) --补题
链接 直接用数组记录每个字母的个数即可 #include<bits/stdc++.h> using namespace std; int a[26] = {0}; int b[26] = ...
- Educational Codeforces Round 78 (Rated for Div. 2) D. Segment Tree
链接: https://codeforces.com/contest/1278/problem/D 题意: As the name of the task implies, you are asked ...
- Educational Codeforces Round 78 (Rated for Div. 2) B. A and B
链接: https://codeforces.com/contest/1278/problem/B 题意: You are given two integers a and b. You can pe ...
- Educational Codeforces Round 78 (Rated for Div. 2) A. Shuffle Hashing
链接: https://codeforces.com/contest/1278/problem/A 题意: Polycarp has built his own web service. Being ...
- Educational Codeforces Round 78 (Rated for Div. 2)B. A and B(1~n的分配)
题:https://codeforces.com/contest/1278/problem/B 思路:还是把1~n分配给俩个数,让他们最终相等 假设刚开始两个数字相等,然后一个数字向前走了abs(b- ...
- Educational Codeforces Round 78 (Rated for Div. 2) 题解
Shuffle Hashing A and B Berry Jam Segment Tree Tests for problem D Cards Shuffle Hashing \[ Time Lim ...
- Educational Codeforces Round 78 (Rated for Div. 2) C - Berry Jam(前缀和)
随机推荐
- Application类-欢迎页(初始界面)
在程序界面显示前,如果我们处理了很多耗时操作,这个时候给用户提示一个欢迎页便是十分友好的.WPF为我们提供了这个特性: 第一种方法:通过设置图片资源的生成操作 粘贴一个图片到我们的项目中 在解决方案管 ...
- microsoft.extensions.logging日志组件拓展(保存文本文件)
Microsoft.Extensions.Logging 日志组件拓展 文件文本日志 文件文本日志UI插件 自定义介质日志 Microsoft.Extensions.Logging.File文件文本日 ...
- 使用order by和group by的分析
mysql 写sql的顺序: select -> from-> where->group by->having->order by. 但mysql的解析 ...
- java DES转C#DES加密解密
一个程序用到java的cn.core.jar加密的,需要在.NET 中解密,发现JAVA的des算法与C#的有点区别. 自己不太懂加密解密算法,所以找了个省事的方法,用IKVM.NET,用这个将cn. ...
- RFID相关知识总结(超高频UHF)
RFID标签分类 1.LF(Low frequency) 低频 频段范围: 125 KHz-135KHz(ISO18000-2) 常见应用:该频段特点是具有良好的物体穿透能力.广泛应用于进出管理.门禁 ...
- PIE SDK 精度分析(分类后处理)
1.算法功能简介 遥感图像分类精度分析通常把分类图与标准数据进行比较,然后用正确分类的百分比来表示分类的精度. PIE SDK支持算法功能的执行,下面对精度分析算法功能进行介绍. 2.算法功能实现说明 ...
- laravel 框架配置404等异常页面的方法详解(代码示例)
本篇文章给大家带来的内容是关于laravel 框架配置404等异常页面的方法详解(代码示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 在Laravel中所有的异常都由Handl ...
- PAT 1026程序运行时间
PAT 1026程序运行时间 要获得一个 C 语言程序的运行时间,常用的方法是调用头文件 time.h,其中提供了 clock() 函数,可以捕捉从程序开始运行到 clock() 被调用时所耗费的时间 ...
- 解决 new file()在IOS下不兼容 的问题
最近 做项目,做的要是拍照后上传相片,以file格式上传..所以 拍照 后用canvas生成base64格式再转file..在PC和安卓都是没有问题,到IOS上面不行..new file后就是生成一个 ...
- webUploader大文件断点续传学习心得 多文件
二.Jsp代码: <!-- 断点续传 start--> <!-- 隐藏域 实时保存上传进度 --> <input id="jindutiao" t ...