链接

直接用数组记录每个字母的个数即可

#include<bits/stdc++.h>

using namespace std;

int a[26] = {0};
int b[26] = {0}; int judge()
{
//cout<<"111"<<endl;
for (int i = 0; i < 26; ++i)
{
if (a[i]!=b[i])
{
return 0;
}
}
return 1;
}
int main()
{
//ios::sync_with_stdio(false);
int t;
cin>>t;
char p1[101],p2[101];
int flag = 0;
while(t--)
{
cin>>p1;
cin>>p2;
flag = 0;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
int len = strlen(p1);
if (len >strlen(p2))
{
cout<<"NO"<<endl;
continue;
}
else
{
for (int i = 0; i < len; ++i) //先算出一个值
{
a[p1[i]-'a'] ++;
b[p2[i]-'a'] ++;
} for (int i = 0; i<(strlen(p2)-strlen(p1)); ++i)
{
// for (int i = 0; i < 26; ++i)
// {
// cout<<b[i]<<endl;
// }
if(judge())
{
flag = 1;
break;
//cout<<"111"<<endl;
}
else{
b[p2[i]-'a'] -= 1;
b[p2[i+len]-'a'] += 1;
//cout<<p2[i]<<endl;
} } }
if (judge())
{
flag = 1;
}
if (flag)
{
cout<<"YES"<<endl;
}
else
cout<<"NO"<<endl;
} return 0;
}





链接

一直给小的数加,直到大于等于大的那个数,这个时候就可能出现这种情况

1. 超过了一个偶数(0也算)

2. 超过了一个奇数,当前加到的数是奇数

3. 超过了一个奇数,当前加的是偶数

分析可以发现,如果超过了一个偶数,肯定可以从前面加的数里面取这个数的一半的那个数来调平。所以次数就是i

但是如果超过的是奇数,那么是不可能调平的,因为奇数不可能分解成相等的整数(可以思考一下,我们只需要调平超出的数就行)

所以分析可知,必须使得超出的数是偶数,那么此时如果i是奇数,结果就是i+2, i是偶数结果就是i+1

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () { int t;
cin >> t;
while(t--){
ll a,b;
cin >> a >> b;
if(a < b) {
swap(a, b);
}
ll c = a - b;
int i = 0;
ll s = 0;
if(c==0)
{
cout<<0<<endl;
continue;
}
while(1){
i++;
s = i * (i + 1) / 2;
if(s < c) {
continue;
}
else
{
if((s-c)&1)
{
if(i&1)
{
cout<<i+2<<endl;
break;
}
else
{
cout<<i+1<<endl;
break;
}
}
else
{
cout<<i<<endl;
break;
}
}
}
} }





链接

分前半段和后半段求前缀和,对前半段预处理后。遍历后半段的去找最小值。
#include<bits/stdc++.h>

using namespace std;

int a[200000];
int b[400000];
int vis[400000]; int main(int argc, char const *argv[])
{
int t;
ios::sync_with_stdio(false);
cin>>t;
while(t--)
{
int n;
cin>>n;
memset(b, 0x3f, sizeof(b));
memset(vis,0,sizeof(vis));
int count = 0;
for (int i = 1; i<=n; ++i)
{
cin>>a[i];
a[i] = a[i]==2? -1:1;
count += a[i];
} //记录下来了
a[n+1] = 0;
b[200000] = 0;
vis[200000] = 1;
for (int i = n; i >=1; --i) //前缀和,前半部分是要倒着求得
{
a[i] += a[i+1];
if(!vis[200000+a[i]]) //记录下到达每个位置的最近的放步数
{
vis[200000+a[i]] = 1;
//cout<<200000+a[i]<<" "<<n-i+1<<endl;
b[200000+a[i]] = n-i+1; //给他赋值,记录最快速到达的放法
}
}
a[0] = 0;
for (int i = 1; i <= n; ++i)
{
cin>>a[i];
a[i] = a[i] == 2? -1:1;
count += a[i];
a[i] += a[i-1]; //后半部分正着求前缀和
}
int mi = b[200000+count]; //表示全部从左边取
for (int i = 1; i <= n; ++i)
{
//cout<<mi<<endl;
mi = min(mi, b[count-a[i]+200000]+i);
}
if (count)
{
cout<<mi<<endl;
}
else
{
cout<<0<<endl;
}
}
return 0;
}

Educational Codeforces Round 78 (Rated for Div. 2) --补题的更多相关文章

  1. Educational Codeforces Round 74 (Rated for Div. 2)补题

    慢慢来. 题目册 题目 A B C D E F G 状态 √ √ √ √ × ∅ ∅ //√,×,∅ 想法 A. Prime Subtraction res tp A 题意:给定\(x,y(x> ...

  2. Educational Codeforces Round 68 (Rated for Div. 2)补题

    A. Remove a Progression 签到题,易知删去的为奇数,剩下的是正偶数数列. #include<iostream> using namespace std; int T; ...

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

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

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

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

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

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

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

  9. Educational Codeforces Round 78 (Rated for Div. 2)

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

随机推荐

  1. java8 的files、path类相关文件遍历API

    Path的两种初始化(应该还有别的方式) Path file = new File(path).toPath(); Paths.get 判断是文件.是目录 Files.isRegularFile(fi ...

  2. linux环境搭配

    1.linuxLinux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和Unix的多用户.多任务.支持多线程和多CPU的操作系统.它能运行主要的Unix工具软件.应用程序和网络协议 ...

  3. java异常处理机制详解

    java异常处理机制详解 程序很难做到完美,不免有各种各样的异常.比如程序本身有bug,比如程序打印时打印机没有纸了,比如内存不足.为了解决这些异常,我们需要知道异常发生的原因.对于一些常见的异常,我 ...

  4. 洛谷 P3373 【模板】线段树 2

    洛谷 P3373 [模板]线段树 2 洛谷传送门 题目描述 如题,已知一个数列,你需要进行下面三种操作: 将某区间每一个数乘上 xx 将某区间每一个数加上 xx 求出某区间每一个数的和 输入格式 第一 ...

  5. golang数据结构之插入排序

    //InsertSort 插入排序 func InsertSort(arr *[]int) { ; i < len(arr); i++ { insertVal := (*arr)[i] inse ...

  6. Batchnorm原理详解

    Batchnorm原理详解 前言:Batchnorm是深度网络中经常用到的加速神经网络训练,加速收敛速度及稳定性的算法,可以说是目前深度网络必不可少的一部分. 本文旨在用通俗易懂的语言,对深度学习的常 ...

  7. python做中学(三)条件编译的用法

    C代码中经常使用条件编译,python中该怎么用呢?Python没有像C或C或Java甚至Java一样编译,python文件被“即时”编译,您可以将其视为类似于Basic或Perl的解释语言 只需使用 ...

  8. python-13-集合增删查

    前言 集合:可变的数据类型,但元素必须是不可变的数据类型,无序不重复,既可哈希.所以python的集合是不能进行修改的,只有增删查.可哈希.不可变数据类型有:元组.bool.int.str 一.增 1 ...

  9. 详解JAVA8函数式接口{全}

    1: 函数式接口 1.1 概念 1.2 格式 1.3@FunctionalInterface注解 1.4 调用自定义函数接口 2:函数式编程 2.1:lambda的延迟执行 2.2 使用Lambda作 ...

  10. Jmeter-Java请求实战

    1.1. jmeter-java插件实现接口测试 (linux /mysql/rabbit-mq) 本次需要准备环境 Eclipse+jdk8 Jmeter Python 1.1.1. Rabbit- ...