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 ...
随机推荐
- [PHP] 解决php中上传大文件的错误
修改nginx配置文件,下面这个参数client_max_body_size 110M; 修改php配置文件中下面两个参数在php.ini中找到下面两个配置,配置项给改大,如果找不到php.ini的位 ...
- 【转载】Spring学习(1)——快速入门--2019.05.19
原文地址:https://www.cnblogs.com/wmyskxz/p/8820371.html 认识 Spring 框架 Spring 框架是 Java 应用最广的框架,它的成功来源于理念 ...
- docker搭建kafka环境&&Golang生产和消费
docker 搭建kafka环境 version: '2' services: zk1: image: confluentinc/cp-zookeeper:latest hostname: zk1 c ...
- spring+eureka+zuul
最近在看一个关于spring+eureka+zuul的教学视频,终于明白了eureka是用于提供服务注册和发现的service,通过eureka各个service可以知道其他service,这样就隔离 ...
- 第04组 Beta冲刺(1/5)
队名:new game 组长博客:戳 作业博客:戳 组员情况 鲍子涵(队长) 过去两天完成了哪些任务 验收游戏素材 学习Unity 2D Animation系统 接下来的计划 制作游戏需要的人物动画 ...
- npm查看本地包版本号和远程包的版本号
npm 查看远程包 第一种方法: npm info <packageName> 第二种方法: npm view <packageName> versions --json np ...
- 《细说PHP》第四版 样章 第23章 自定义PHP接口规范 2
23.1.3 接口的应用和优势 API是一些预先定义的函数,目的是提供应用程序与开发人员基于某软件或硬件得以访问一组例程的能力,而又无须访问源码,或理解内部工作机制的细节.接口应用的一些常见场景如下 ...
- ES6入门 阮一峰
ECMAScript 6 入门 http://es6.ruanyifeng.com/#README 在线ES6转ES5 https://es6console.com/k11vgg1r/
- WebJar的打包和使用
前言 WebJar官网:https://www.webjars.org/,对于任何与Servlet 3兼容的容器,WEB-INF/lib目录中的webjar都会自动作为静态资源提供.这是因为WEB-I ...
- C#数组2(多维数组)
using System; namespace ConsoleApp3 { struct WuGong { public string Name; public int Attack; } class ...



