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. Nginx 本地建立负载均衡(Windows环境)

    需求: 现在有个需求:两台服务器,建立负载均衡. A服务器:IP:localhost:负载均衡主服务器:代理本地文件夹D:\\SampleData B服务器:IP:10.10.10.10:代理本地文件 ...

  2. ArcGIS 发布Feature服务

    运行环境: Win10 ArcGIS10.4 具体操作: 1.打开ArcMap,加载sde中导入的文件,也可以加载shp数据源指向sde中文件 2.保存成mxd,然后点share as-Service ...

  3. 正确理解 PHP 的重载

    PHP 的重载跟 Java 的重载不同,不可混为一谈.Java 允许类中存在多个同名函数,每个函数的参数不相同,而 PHP 中只允许存在一个同名函数.例如,Java 的构造函数可以有多个,PHP 的构 ...

  4. 《VueRouter爬坑第三篇》-嵌套路由

    VueRouter系列的文章示例编写时,项目是使用vue-cli脚手架搭建. 项目搭建的步骤和项目目录专门写了一篇文章:点击这里进行传送 后续VueRouter系列的文章的示例编写均基于该项目环境. ...

  5. Dockerfile构建私有镜像

    构建第一个镜像 镜像的定制实际上就是定制每一层所添加的配置,文件.我们可以把每一层修改,安装,构建,操作的命令都写入一个脚本,这个脚本就是Dockerfile.Dockerfile是一个文本文件,其内 ...

  6. C# delegate和C# event

    在基于Windows平台的程序设计中,事件(event)是一个很重要的概念.因为在几乎所有的Windows应用程序中,都会涉及大量的异步调用,比如响应点击按钮.处理Windows系统消息等,这些异步调 ...

  7. 错误 找不到Xcode No such file or directory

  8. ThinkPHP5入门(基础篇)

    ThinkPHP是一个快速.简单的基于MVC和面向对象的轻量级PHP开发框架,自2006年诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简代码的同时,尤其注重开发体验和易用性,并且拥有众多的 ...

  9. 16.Django学习之文件上传和下载

    上传就这么六步! 一. settings配置文件中配置 MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'medias').repl ...

  10. 用workspace管理工程,并解决多静态库依赖

    from:http://www.cnblogs.com/perryxiong/p/3759818.html   最近我在项目中遇到一些工程之间的管理问题. 模型: 其中 库A 是一个公共的基础静态库, ...