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记录位置,求除留下最大数量,然后用2
n减去,输出就可以了

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

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

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

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

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

  5. 【cf比赛记录】Educational Codeforces Round 78 (Rated for Div. 2)

    比赛传送门 A. Shuffle Hashing 题意:加密字符串.可以把字符串的字母打乱后再从前面以及后面接上字符串.问加密后的字符串是否符合加密规则. 题解:字符串的长度很短,直接暴力搜索所有情况 ...

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

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

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

  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. 元数据管理的重要性 - xms

    什么是元数据?引用百科的描述就是:元数据(Metadata),又称中介数据.中继数据,为描述数据的数据(data about data),主要是描述数据属性(property)的信息: 看起来有点抽象 ...

  2. 【Luogu P3375】字符串匹配KMP算法模板

    Luogu P3375 模式串:即题目中的S2所代表的意义 文本串:即题目中的S1所代表的意义 对于字符串匹配,有一种很显然的朴素算法:在S1中枚举起点一位一位匹配,失配之后起点往后移动一位,从头开始 ...

  3. 常见HTTP请求头和响应头

    2. 常用的HTTP请求头 协议头 说明 示例 状态 Accept 可接受的响应内容类型(Content-Types). Accept: text/plain 固定 Accept-Charset 可接 ...

  4. 前端API层架构,也许你做得还不够

    上午好,今天为大家分享下个人对于前端API层架构的一点经验和看法.架构设计是一条永远走不完的路,没有最好,只有更好.这个道理适用于软件设计的各个场景,前端API层的设计也不例外,如果您觉得在调用接口时 ...

  5. overflow属性值

    overflow属性的可取值有四种:visible.hidden.scroll.auto visible:不裁剪溢出的内容.浏览器把溢出来的内容呈现在其内容元素的显示区域以外的地方,全部内容在浏览器的 ...

  6. Spring(Bean)1

    Spring支持3种依赖注入的方式 (DI依赖注入)*属性注入 (配置bean set方法注入) <bean id="car" class="spring.bean ...

  7. Oracle procedure 在命令行里面执行出错

    One procedure do well in SQL developer but error during exceute it under sqlplus command line: Remem ...

  8. powerline字体安装

    安装命令 git clone https://github.com/powerline/fonts ./install.sh 了解powerline ->美化自己的命令行环境,增加漂亮的状态行, ...

  9. 【nodejs原理&源码赏析(3)】欣赏手术级的原型链加工艺术

    [摘要] 学习经典代码中的prototype加工 示例代码托管在:http://www.github.com/dashnowords/blogs 好的代码都差不多,烂的代码却各有各的烂法. 一. 概述 ...

  10. npm 安装/删除/发布/更新/撤销 发布包

    目录 一. npm安装包 1.1 什么时候用本地/全局安装? 1 当你试图安装命令行工具的时候,例如 grunt CLI的时候,使用全局安装 2. 当你试图通过npm install 某个模块,并通过 ...