A题

给出n对串,求s1,是否为s2一段连续子串的重排,串长度只有100,从第一个字符开始枚举,sort之后比较一遍就可以了;

  1. char s1[200],s2[200],s3[200];
  2. int main() {
  3. int q;
  4. cin >> q;
  5. while(q--) {
  6. cin >> s1 >> s2;
  7. int s11 = strlen(s1),s22 = strlen(s2),i;
  8. sort(s1,s1+s11);
  9. s3[s11] = '\0';
  10. for(i = 0; i + s11 <= s22; i++) {
  11. strncpy(s3,s2+i,s11);
  12. sort(s3,s3+s11);
  13. if(strcmp(s1,s3) == 0) {
  14. cout << "YES" << endl;
  15. break;
  16. }
  17. }
  18. if(i + s11 > s22) cout << "NO" << endl;
  19. }
  20. return 0;
  21. }

B题

给出两个数a和b,第i次操作可以把i加给任意两个数,求将两个数变为相等的最小操作次数

把i求和得来的数sum和cha = abs(a-b),相加,让sum和cha的和对2取模为0并且sum >= cha(如果小于的话全部加到比较小的数上也无法相等),输出i就可以了。

  1. int main() {
  2. int q;
  3. cin >> q;
  4. while(q--) {
  5. int a,b;
  6. cin >> a >> b;
  7. ll min = 0,cha = abs(a-b);
  8. int i = 1;
  9. while(cha > min || (cha + min)%2 != 0) min+=i++;
  10. cout << i-1 << endl;
  11. }
  12. return 0;
  13. }

C题

给出2n个罐子,里面分别装着蓝色和红色的东西,分别从n和n+1之间向两边拿走一些,问最少需要拿走多少罐,就可以让两种颜色的数量相等。

输入的2改为-1,求前缀和和后缀和,用map记录位置,求除留下最大数量,然后用2
n减去,输出就可以了

  1. map<int,int> mmp;
  2. int a[MAXN],lsum[MAXN],rsum[MAXN];
  3. int main() {
  4. int q;
  5. cin >> q;
  6. while(q--) {
  7. mmp.clear();
  8. int n;
  9. cin >> n;
  10. for(int i = 0; i <= 2*n+1; i++) {
  11. lsum[i] = 0;
  12. rsum[i] = 0;
  13. }
  14. for(int i = 1; i <= 2 * n; i++) {
  15. cin >> a[i];
  16. if(a[i] == 2) a[i] = -1;
  17. }
  18. for(int i = 1; i <= n; i++) {
  19. lsum[i] = lsum[i-1] + a[i];
  20. }
  21. for(int i = 2*n; i >= n+1; i--) {
  22. rsum[i] = rsum[i+1] + a[i];
  23. }
  24. for(int i = 0; i <= n; i++) {
  25. mmp[lsum[i]] = i;
  26. }
  27. int ans = 0;
  28. for(int i = 2*n+1; i >= n+1; i--) {
  29. int t = -rsum[i];
  30. if(mmp.count(t)) ans = max(ans,mmp[t]+2*n - i + 1);
  31. }
  32. cout << 2*n - ans << endl;
  33. }
  34. }

艰难的补题之旅开始了

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. 2019-10-16:渗透测试,基础学习,burpsuit笔记

    maccms10后门分析下载网址,是假官网http://www.maccmsv10.com/download.htmlMaccms10基于php+mysql的maccms,是苹果的内容管理,方便使用, ...

  2. 【2018寒假集训Day 1】【位运算】生成字符串

    生成字符串(strs) [问题描述] 假设字符串只由字符“0”,“1”,“”组成,其中字符“”表示该字符可由 字符“0”或“1”替代. 现有一些字符串,根据这些字符串生成所有可生成的字符串.如: {1 ...

  3. DVWA学习之SQL注入

    DVWA学习之SQL注入 环境工具 dvwa 1.9 phpstudy firefox burpsuite 实验步骤 一.设置安全级别为LOW 1. 登录DVWA,并将安全级别设置为LOW 2. 进入 ...

  4. Maven搭建SpringMvc

    Maven搭建SpringMvc,只需跟着一步步操作 项目结构 1 创建Maven项目 index,jsp报错不用管,配置完pom就好了,也可以直接删除掉 2 pom.xml添加依赖 <depe ...

  5. 测试访问apiserver状态

    目录 前言 创建admin证书和私钥 分发kubeconfig文件 检查集群信息 授权kube-apiserver访问kubelet API的权限 前言 到这里,ETCD集群.kube-nginx + ...

  6. redis - redis数据结构与API

    通用命令 keys:遍历所有的key[keys一般不再生产环境使用],时间复杂度O(n) keys * keys he* keys he[h-l]* keys ph? dbsize:计算key的总数, ...

  7. vue实例化过程

    我们在用vue进行开发项目时,是否存在疑惑,new Vue(xxx)的过程中,究竟发生了什么?定义的数据,是如何绑定到视图上的?本篇主要介绍在实例化vue时,主要做了哪些事,文章比较长,主要篇幅内容为 ...

  8. 顺序队列与链式队列--C语言实现

    关于队列,因为我自己在平时使用不多,所以在这里直接将队列的两种存储方式放在一起,作为一篇随笔,这两份代码均可直接运行,亲测.注释写的应该也算比较详细了,就不过多的解释了 顺序队列 #include&l ...

  9. Oracle_视图_索引_plsql_游标_存储过程_存储函数_触发器

    -- 感觉有用点个赞呗^v^ select * from emp; drop view persin_vw;--删除视图 create table emp as select * from scott ...

  10. luogu P2946 [USACO09MAR]牛飞盘队Cow Frisbee Team

    题目背景 老唐最近迷上了飞盘,约翰想和他一起玩,于是打算从他家的N头奶牛中选出一支队伍. 每只奶牛的能力为整数,第i头奶牛的能力为R i .飞盘队的队员数量不能少于 1.大于N.一 支队伍的总能力就是 ...