比赛传送门


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)的更多相关文章

  1. 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 ...

  2. Educational Codeforces Round 78 (Rated for Div. 2)

    A题 给出n对串,求s1,是否为s2一段连续子串的重排,串长度只有100,从第一个字符开始枚举,sort之后比较一遍就可以了: char s1[200],s2[200],s3[200]; int ma ...

  3. Educational Codeforces Round 78 (Rated for Div. 2) --补题

    链接 直接用数组记录每个字母的个数即可 #include<bits/stdc++.h> using namespace std; int a[26] = {0}; int b[26] = ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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- ...

  8. 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 ...

  9. Educational Codeforces Round 78 (Rated for Div. 2) C - Berry Jam(前缀和)

随机推荐

  1. [转帖]从零开始入门 K8s | 手把手带你理解 etcd

    从零开始入门 K8s | 手把手带你理解 etcd https://zhuanlan.zhihu.com/p/96721097 导读:etcd 是用于共享配置和服务发现的分布式.一致性的 KV 存储系 ...

  2. 【07】Kubernets:资源清单(控制器 - DaemonSet)

    写在前面的话 前面讲解了 Pod / ReplicaSet / Deployment 的资源清单,我们这里谈一下 DaemonSet 的资源清单. 之前说过,DaemonSet 控制器能够保证资源在每 ...

  3. Application类-应用程序生命周期

    1.创建Application对象 新建WPF程序后,排除掉WPF自动创建的App.xaml,我们自定义一个类,在该类的Main()方法中,创建Application对象,然后调用创建一个窗口对象,最 ...

  4. Linux 监控之 IO

    简单介绍下 Linux 中与 IO 相关的内容. 简介 可以通过如下命令查看与 IO 相关的系统信息. # tune2fs -l /dev/sda7 ← 读取superblock信息 # blockd ...

  5. Linux 目录简介

    这里以Centos7为例: 使用tree命令查看/目录结构如下: 下面我们主要探讨如下主要目录: /:根目录不必多说,文件系统的最顶端,存放系统所有目录. bin:该目录主要存放系统运行所需要的重要命 ...

  6. Exif认识(二)

    通过php获取exif信息后,像光圈和快门的值还需要转换下,才是我们常用看得懂的值 ApertureValue的值: 拍照时镜头的光圈. 单位是 APEX. 为了转换成普通的 F-number(F-s ...

  7. Visual Studio Code创建C#项目

    Visual Studio Code是一个支持跨平台的文本编辑器,同其他文本文本编辑器一样,不但占用磁盘空间小,性能也比较快:近几年由于不断的升级和许多开发者提供大量的插件,它已经成为了一个非常强大的 ...

  8. iOS11里判断Safari浏览器是无痕模式还是正常模式?

    var isPrivate = false; try { window.openDatabase(null, null, null, null); } catch (_) { isPrivate = ...

  9. Java代码中可以优化性能的小细节

    避免对boolean类型的判定 反例: 12 if("a".equles("a")==true)`{} 正例: 12 if(Objects.equles(&qu ...

  10. 一个判断js数据类型的函数

    function judgeType(change) { if (arguments.length == 0) { return '0';//无参数传入 } if (change === null) ...