【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(前缀和)
随机推荐
- 解决SpringBoot无法读取js/css静态资源的新方法
前言 作为依赖使用的SpringBoot工程很容易出现自身静态资源被主工程忽略的情况.但是作为依赖而存在的Controller方法却不会失效,我们知道,Spring MVC对于静态资源的处理也不外乎是 ...
- vue引入bootstrap、jquery
在进行vue的学习,项目中需要引入bootstrap.jquery的步骤. 一.引入jQuery 在当前项目的目录下(就是package.json),运行命令 cnpm install jquery ...
- php 安装xdebug扩展和配置phpstorm断点
参考链接:安装xdebug扩展和配置phpstorm断点
- table中td文字超出长度用省略号隐藏超出内容,鼠标点击内容全部显示
1,设置css样式 <style>table {width: 100%;float: left;table-layout:fixed;width:600px;border:1px soli ...
- 01 .NET CORE 2.2 使用OCELOT -- 简单使用
目前参考两篇文章,已实现基本的ocelot的网关功能. https://www.cnblogs.com/xlxr45/p/11320988.html https://www.jianshu.com/p ...
- 3-RocketMQ 简单梳理 及 集群部署笔记
原文:https://www.cnblogs.com/kevingrace/p/9015836.html 一.RocketMQ 基础知识介绍Apache RocketMQ是阿里开源的一款高性能.高吞吐 ...
- 很全的vue插件汇总,赶紧收藏下(转)
Vue是一个构建数据驱动的 web 界面的渐进式框架.Vue.js 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件特别整理了常用的vue插件,来了个大汇总,方便查找使用,便于工作 ...
- cocos2d-js中jsc逆向为js攻略
笔记: 主要发现有两个工具 存档记录一下 https://github.com/OEDx/cocos-jsc-endecryptor python的 解密需要秘钥 推荐这个: https://git ...
- Caml 多表关联查询
using (SPSite site = new SPSite(SiteUrl)) { using (SPWeb web = site.RootWeb) { SPQuery query = new S ...
- 电信NBIOT 1 - 数据上行(中国电信开发者平台对接流程)
电信NBIOT 1 - 数据上行(中国电信开发者平台对接流程) 电信NBIOT 2 - 数据上行(中间件获取电信消息通知) 电信NBIOT 3 - 数据下行 电信NBIOT 4 - NB73模块上行测 ...