链接

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

#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自定义指令笔记

    https://cn.vuejs.org/v2/guide/custom-directive.html 在vue中,有时候我们会把抽象的方法封装为一个自定义指令,多个地方共用 比如:拖拽指令 < ...

  2. mysql导出数据的几种形式-待更新

    1.导出某个数据库的某张表,添加where条件 mysqldump -u [用户名] -p  -h [ip地址]  --default-character-set=utf8 [数据库名] [表名] - ...

  3. java图形界面 计算器实现

    编写程序实现一个简单计算器的基本功能,具体可以模仿Windows附件中的计算器或模拟常见的实物计算器. package beizi; import java.awt.EventQueue; impor ...

  4. 【Oracle命令 】使用的sql语句之分组查询(group by)

    由于本人并未对oracle数据库进行深入了解,但是工作中又需要知道一些基础的sql,所以记录下操作的sql语句.方便日后查看 1.将序列号作为分组查询的条件,再将查询出来的结果进行筛选. select ...

  5. 洛谷P5322 (BJOI 2019) DP

    ### 题目链接 ### 分析: 1.用 vector<int> v[i] 来存 i 城堡, s 个对手所安排的士兵数量. 2.设 dp[i][j] 表示 i 城堡前,在当前最大派兵量为  ...

  6. json递归查询

    主体: class json_search(): '''递归查询依赖key''' def search_key(self,data,key): self.data = data self.key_va ...

  7. 如何在本地开发Composer包

    如何在本地开发Compoer包 周煦辰 2019-05-26 记录一下如何在本地开发一个Composer包,以及如何发布到Packgist. 假设你要开发一个名叫xuchen/biubiubiu的包. ...

  8. Java设计模式:Abstract Factory(抽象工厂)模式

    概念定义 抽象工厂(Abstract Factory)模式提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类. 抽象工厂模式中,系统的产品有多于一个的产品族(一个产品族里定义多个产品) ...

  9. wp.editor.initialize 配置案例

    wp.editor.initialize ( 'EditorTextArea' , { tinymce: { wpautop: to true , theme: 'modern' , skin: 'l ...

  10. 使用zabbix监控oracle的后台日志

    本文将介绍如何使用zabbix监控oracle的后台日志,当oracle后台日志出现“ORA-”或“Error”时,第一时间将该信息报警出来 zabbix agent端 以下所有操作均用root执行 ...