链接

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

#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. vue踩坑--细节决定成败

    1.错误示例 . 2.错误的地方 3.修改后代码 4.错误分析

  2. Day7 - Python基础7 面向对象

    本节内容: 1:概述 2:类.对象和方法的创建 3:面向对象三大特性,封装.继承和多态. 4:面向对象中高级篇:类成员:字段.方法.属性 5:类成员的修饰符 6:类的特殊成员 1.概述 面向过程:根据 ...

  3. CF53E Dead Ends

    CF53E Dead Ends 洛谷评测传送门 题目描述 Life in Bertown has become hard. The city has too many roads and the go ...

  4. 2019CSP-J/S受虐记

    emmmm...... 今年noip很波折,我从7月开始准备 但CCF居然停了noip,这搞得我很迷茫,CCF你在干什么! 然后又恢复了,这有搞得我很懵逼?(还改名叫csp了) 就换了个名,CCF你搞 ...

  5. 图片(jpg,png,tif等)批量转dicom(dcm)格式

    简介 医学领域专用工具,千金难求,可以批量把jpg.png.bmp.tif图片转换为dicom(dcm)格式,并且保持原有顺序,同时支持嵌入部分重要的dicom元数据,比如:病人姓名,病人生日等. 将 ...

  6. php 截取字符串 strstr 和strrchr

    截取字符串 strstr 和strrchr 结果:(其中之一) strstr : 执行时间在0.10 - 0.19 之间 strrchr : 执行时间在0.095 - 0.19 之间 结论:从数十次执 ...

  7. LeetCode 1:两数之和 Two Sum

    题目: 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这个数组中 ...

  8. Linux 部署redis集群

    下载Redis 下载网址 http://www.redis.cn/download.html Redis需要gcc环境(如果已经有该环境跳过此步骤) yum install gcc-c++ 安装Red ...

  9. 在Unity中使用自定义宏

    最近写AVG工具时有这样的功能需求,AVG的角色可以支持动态的Spine动画,当没有Spine动画时采用默认的立绘图片替代. 这时在脚本中就可以采用自定义的宏来实现: 例如: #if VNSpine ...

  10. 使用suds模块进行封装,处理webservice类型的接口

    import json from suds.client import Client class HandleWebservice: ''' 定义一个webservice类型的接口处理类 ''' de ...