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. Openlayers Projection导致经纬度颠倒问题

    问题: openlayers3调用TileWMS接口,实现Openlayers加载Geoserver转发的ArcGIS切片时,web墨卡托(wkid3857)没有问题,但是WGS84(wkid4326 ...

  2. 协议分层(因特网5层模型)及7层OSI参考模型

    目录 因特网5层模型及7层OSI参考模型 分层的体系结构: 应用层(软件) 运输层(软件) 网络层(硬件软件混合) 链路层(硬件) 物理层(硬件) OSI模型 表示层 会话层 封装 因特网5层模型及7 ...

  3. 掌握Python系统管理-调试和分析脚本2- cProfile和timeit

    调试和分析在Python开发中发挥着重要作用. 调试器可帮助程序员分析完整的代码. 调试器设置断点,而剖析器运行我们的代码,并给我们执行时间的详细信息. 分析器将识别程序中的瓶颈.我们将了解pdb P ...

  4. JSONPath小试牛刀之Snack3

    最近在网上看了些JSONPath的入门例子.打算用Snack3这个框架写写例子.json path对`JSON的处理绝对是神器. 1.准备JSON字符串 { "store": { ...

  5. Activiti工作流框架学习(一)之通用数据表详细介绍

    文/朱季谦 Activiti工作流引擎自带了一套数据库表,这里面有一个需要注意的地方: 低于5.6.4的MySQL版本不支持时间戳或毫秒级的日期.更糟糕的是,某些版本在尝试创建此类列时将引发异常,而其 ...

  6. 最全最新🇨🇳中国【省、市、区县、乡镇街道】json,csv,sql数据

    中华人民共和国行政区划代码 中华人民共和国行政区划(五级):省级.地级.县级.乡级和村级. 来自中华人民共和国民政部,用于查询中国省,市和区数据的网站. 中华人民共和国行政区划代码,更新时间:2019 ...

  7. day20190904一号店网页HTML+CSS

    1.知识要理一理.梳理.当天讲了什么内容?当天我学习到了什么内容?看懂.所有的学习型从模仿开始.1.看懂代码,看懂思路,学思路,多问自己问题,为什么要这么写?下一步为什么要这么写?因 果.2.多练多敲 ...

  8. Hadoop streaming脚本中约束关系参数详解

    1 -D mapred.output.key.comparator.class=org.apache.hadoop.mapred.lib.KeyFieldBasedComparator \ 2 -D ...

  9. P3954 成绩

    题目描述 牛牛最近学习了C++入门课程,这门课程的总成绩计算方法是: 总成绩=作业成绩\times 20\%+×20%+小测成绩×30\%+×30%+期末考试成绩\times 50\%×50% 牛牛想 ...

  10. AWK工具 使用介绍

    第6周第5次课(4月27日) 课程内容: 9.6/9.7 awk扩展把这里面的所有练习题做一下http://www.apelearn.com/study_v2/chapter14.html 9.6/9 ...