Educational Codeforces Round 78 (Rated for Div. 2) --补题
直接用数组记录每个字母的个数即可
#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) --补题的更多相关文章
- Educational Codeforces Round 74 (Rated for Div. 2)补题
慢慢来. 题目册 题目 A B C D E F G 状态 √ √ √ √ × ∅ ∅ //√,×,∅ 想法 A. Prime Subtraction res tp A 题意:给定\(x,y(x> ...
- Educational Codeforces Round 68 (Rated for Div. 2)补题
A. Remove a Progression 签到题,易知删去的为奇数,剩下的是正偶数数列. #include<iostream> using namespace std; int T; ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 【cf比赛记录】Educational Codeforces Round 78 (Rated for Div. 2)
比赛传送门 A. Shuffle Hashing 题意:加密字符串.可以把字符串的字母打乱后再从前面以及后面接上字符串.问加密后的字符串是否符合加密规则. 题解:字符串的长度很短,直接暴力搜索所有情况 ...
- 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- ...
- Educational Codeforces Round 78 (Rated for Div. 2)
A题 给出n对串,求s1,是否为s2一段连续子串的重排,串长度只有100,从第一个字符开始枚举,sort之后比较一遍就可以了: char s1[200],s2[200],s3[200]; int ma ...
随机推荐
- Linux CentOS 6.5 卸载、tar安装MySQL
卸载系统自带MySQL 1. 查看系统当前是否安装有MySQL rpm -qa|grep -i mysql 2. 卸载当前版本的MySQL yum remove mysql mysql-server ...
- 010.MongoDB备份恢复
一 MongoDB备份 1.1 备份概述 mongodb数据备份和还原主要分为二种,一种是针对于库的mongodump和mongorestore,一种是针对库中表的mongoexport和mongoi ...
- BERT源码分析
一.整体 整个代码文件如下: 二.tensorflow基础 1.tf.expand_dims 作用:给定张量“ input”,此操作将在“ input”形状的尺寸索引“ axis”处插入尺寸为1的尺寸 ...
- 201871010111-刘佳华《面向对象程序设计(java)》第十四周学习总结
201871010111-刘佳华<面向对象程序设计(java)>第十四周学习总结 实验十二 Swing图形界面组件(一) 实验时间 2019-11-29 第一部分:基础知识总结 1.设计 ...
- AcWing 27. 数值的整数次方
地址 https://www.acwing.com/problem/content/description/26/ 题目描述实现函数double Power(double base, int expo ...
- WPF 精修篇 样式继承
原文:WPF 精修篇 样式继承 这个 是新知识 样式可以继承 <Style x:Key="TextBlockStyleBase" TargetType="{x:Ty ...
- Mybatis框架增删改查
一.recourses中核心配置文件mybatis-config.xml 二. recourse中jdbc.properties 三.entity实体类 四.ISmbmsUserDao层 五.ISmb ...
- 实例调用(__call__())
任何类,只需要定义一个__call__()方法,就可直接对实例进行调用 对实例进行直接调用就好比对一个函数进行调用一样 __call__()还可定义参数,所以调用完全可以把对象看成函数,把函数看成对象 ...
- IT兄弟连 HTML5教程 HTML5的学习线路图 第一阶段学习网页制作
学习HTML5技术可并不是简单学会几个新增的标签而已,HTML5现在可以说是前端所有技术的代名词.需要学习的语言和工具不仅多,对于刚接触他们的新人会感觉很乱.另外,前端开发也会细分很多个开发岗位,不同 ...
- apt-get failed:The following signatures were invalid: BADSIG
参考如下链接: https://askubuntu.com/questions/131601/gpg-error-release-the-following-signatures-were-inval ...



