Educational Codeforces Round 78 (Rated for Div. 2)
A题
给出n对串,求s1,是否为s2一段连续子串的重排,串长度只有100,从第一个字符开始枚举,sort之后比较一遍就可以了;
char s1[200],s2[200],s3[200];
int main() {
int q;
cin >> q;
while(q--) {
cin >> s1 >> s2;
int s11 = strlen(s1),s22 = strlen(s2),i;
sort(s1,s1+s11);
s3[s11] = '\0';
for(i = 0; i + s11 <= s22; i++) {
strncpy(s3,s2+i,s11);
sort(s3,s3+s11);
if(strcmp(s1,s3) == 0) {
cout << "YES" << endl;
break;
}
}
if(i + s11 > s22) cout << "NO" << endl;
}
return 0;
}
B题
给出两个数a和b,第i次操作可以把i加给任意两个数,求将两个数变为相等的最小操作次数
把i求和得来的数sum和cha = abs(a-b),相加,让sum和cha的和对2取模为0并且sum >= cha(如果小于的话全部加到比较小的数上也无法相等),输出i就可以了。
int main() {
int q;
cin >> q;
while(q--) {
int a,b;
cin >> a >> b;
ll min = 0,cha = abs(a-b);
int i = 1;
while(cha > min || (cha + min)%2 != 0) min+=i++;
cout << i-1 << endl;
}
return 0;
}
C题
给出2n个罐子,里面分别装着蓝色和红色的东西,分别从n和n+1之间向两边拿走一些,问最少需要拿走多少罐,就可以让两种颜色的数量相等。
输入的2改为-1,求前缀和和后缀和,用map记录位置,求除留下最大数量,然后用2n减去,输出就可以了
map<int,int> mmp;
int a[MAXN],lsum[MAXN],rsum[MAXN];
int main() {
int q;
cin >> q;
while(q--) {
mmp.clear();
int n;
cin >> n;
for(int i = 0; i <= 2*n+1; i++) {
lsum[i] = 0;
rsum[i] = 0;
}
for(int i = 1; i <= 2 * n; i++) {
cin >> a[i];
if(a[i] == 2) a[i] = -1;
}
for(int i = 1; i <= n; i++) {
lsum[i] = lsum[i-1] + a[i];
}
for(int i = 2*n; i >= n+1; i--) {
rsum[i] = rsum[i+1] + a[i];
}
for(int i = 0; i <= n; i++) {
mmp[lsum[i]] = i;
}
int ans = 0;
for(int i = 2*n+1; i >= n+1; i--) {
int t = -rsum[i];
if(mmp.count(t)) ans = max(ans,mmp[t]+2*n - i + 1);
}
cout << 2*n - ans << endl;
}
}
艰难的补题之旅开始了
Educational Codeforces Round 78 (Rated for Div. 2)的更多相关文章
- 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) 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) 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 ...
- 【cf比赛记录】Educational Codeforces Round 78 (Rated for Div. 2)
比赛传送门 A. Shuffle Hashing 题意:加密字符串.可以把字符串的字母打乱后再从前面以及后面接上字符串.问加密后的字符串是否符合加密规则. 题解:字符串的长度很短,直接暴力搜索所有情况 ...
- 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) --补题
链接 直接用数组记录每个字母的个数即可 #include<bits/stdc++.h> using namespace std; int a[26] = {0}; int b[26] = ...
- 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(前缀和)
随机推荐
- 2019-10-16:渗透测试,基础学习,burpsuit笔记
maccms10后门分析下载网址,是假官网http://www.maccmsv10.com/download.htmlMaccms10基于php+mysql的maccms,是苹果的内容管理,方便使用, ...
- 【2018寒假集训Day 1】【位运算】生成字符串
生成字符串(strs) [问题描述] 假设字符串只由字符“0”,“1”,“”组成,其中字符“”表示该字符可由 字符“0”或“1”替代. 现有一些字符串,根据这些字符串生成所有可生成的字符串.如: {1 ...
- DVWA学习之SQL注入
DVWA学习之SQL注入 环境工具 dvwa 1.9 phpstudy firefox burpsuite 实验步骤 一.设置安全级别为LOW 1. 登录DVWA,并将安全级别设置为LOW 2. 进入 ...
- Maven搭建SpringMvc
Maven搭建SpringMvc,只需跟着一步步操作 项目结构 1 创建Maven项目 index,jsp报错不用管,配置完pom就好了,也可以直接删除掉 2 pom.xml添加依赖 <depe ...
- 测试访问apiserver状态
目录 前言 创建admin证书和私钥 分发kubeconfig文件 检查集群信息 授权kube-apiserver访问kubelet API的权限 前言 到这里,ETCD集群.kube-nginx + ...
- redis - redis数据结构与API
通用命令 keys:遍历所有的key[keys一般不再生产环境使用],时间复杂度O(n) keys * keys he* keys he[h-l]* keys ph? dbsize:计算key的总数, ...
- vue实例化过程
我们在用vue进行开发项目时,是否存在疑惑,new Vue(xxx)的过程中,究竟发生了什么?定义的数据,是如何绑定到视图上的?本篇主要介绍在实例化vue时,主要做了哪些事,文章比较长,主要篇幅内容为 ...
- 顺序队列与链式队列--C语言实现
关于队列,因为我自己在平时使用不多,所以在这里直接将队列的两种存储方式放在一起,作为一篇随笔,这两份代码均可直接运行,亲测.注释写的应该也算比较详细了,就不过多的解释了 顺序队列 #include&l ...
- Oracle_视图_索引_plsql_游标_存储过程_存储函数_触发器
-- 感觉有用点个赞呗^v^ select * from emp; drop view persin_vw;--删除视图 create table emp as select * from scott ...
- luogu P2946 [USACO09MAR]牛飞盘队Cow Frisbee Team
题目背景 老唐最近迷上了飞盘,约翰想和他一起玩,于是打算从他家的N头奶牛中选出一支队伍. 每只奶牛的能力为整数,第i头奶牛的能力为R i .飞盘队的队员数量不能少于 1.大于N.一 支队伍的总能力就是 ...