Codeforces Round #619 (Div. 2)
A 题目 You are given three strings a, b and c of the same length n. The strings consist of lowercase English letters only. The i-th letter of a is ai, the i-th letter of b is bi, the i-th letter of c is ci.
For every i (1≤i≤n) you must swap (i.e. exchange) ci with either ai or bi. So in total you’ll perform exactly n swap operations, each of them either ci↔ai or ci↔bi (i iterates over all integers between 1 and n, inclusive).
For example, if a is “code”, b is “true”, and c is “help”, you can make c equal to “crue” taking the 1-st and the 4-th letters from a and the others from b. In this way a becomes “hodp” and b becomes “tele”.
Is it possible that after these swaps the string a becomes exactly the same as the string b?
Input The input consists of multiple test cases. The first line contains a single integer t (1≤t≤100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a string of lowercase English letters a.
The second line of each test case contains a string of lowercase English letters b.
The third line of each test case contains a string of lowercase English letters c.
It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding 100.
Output Print t lines with answers for all test cases. For each test case:
If it is possible to make string a equal to string b print “YES” (without quotes), otherwise print “NO” (without quotes).
You can print either lowercase or uppercase letters in the answers.
翻译 你有三个相同长度的字符串a, b和c。这些字符串由小写的英文字母组成。a的第i个字母是ai, b的第i个字母是bi, c的第i个字母是ci。 对于每个i(1≤i≤n),您必须与ai或bi交换(即交换)ci。所以在总您将执行完全n互换操作,它们中的每一个ci↔ai或ci↔bi(我遍历所有整数1到n,包容)。 例如,如果a是“code”,b是“true”,c是“help”,你可以让c等于“crue”,取a的第1-st个字母和第4个字母,其余的是b的,这样a就变成了“hodp”,b变成了“tele”。 有没有可能在这些交换之后,字符串a变得和字符串b完全一样?
输入 输入由多个测试用例组成。第一行包含一个整数t(1≤t≤100)——测试用例的数量。测试用例的描述如下。 每个测试用例的第一行包含一个小写英文字母a字符串。 每个测试用例的第二行包含一个小写英文字母b的字符串。 每个测试用例的第三行包含一个小写英文字母c的字符串。 保证在每个测试用例中,这三个字符串都是非空的,并且具有相同的长度,长度不超过100。
输出 打印所有测试用例的答案。对于每个测试用例: 如果可以使字符串a与字符串b相等,则打印“YES”(不带引号),否则打印“NO”(不带引号)。 您可以在答案中打印小写或大写字母。
水题签到: 思路:不管怎么交换,如果相应位置三个字符串的字符不一致,那么就不可能得到。
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
int main()
{
int t;
cin >>t;
int res;
while(t--)
{
string a,b,c;
cin>>a>>b>>c;
res=1;
for(int i=0;i<a.size();i++)
{
if(a[i]!=c[i]&&b[i]!=c[i])
{
res=0;
break;
}
}
if(res) cout <<"YES"<<endl;
else cout <<"NO"<<endl;
}
}
B 题目 Dark is going to attend Motarack’s birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers. Dark created that array 1000 years ago, so some elements in that array disappeared. Dark knows that Motarack hates to see an array that has two adjacent elements with a high absolute difference between them. He doesn’t have much time so he wants to choose an integer k (0 k 109) and replaces all missing elements in the array a with k. Let m be the maximum absolute difference between all adjacent elements (i.e. the maximum value of |ai ai+1| for all 1 i n 1) in the array a after Dark replaces all missing elements with k. Dark should choose an integer k so that m is minimized. Can you help him.
Input The input consists of multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.
The first line of each test case contains one integer n (2≤n≤105) — the size of the array a.
The second line of each test case contains n integers a1,a2,…,an (−1≤ai≤109). If ai=−1, then the i-th integer is missing. It is guaranteed that at least one integer is missing in every test case.
It is guaranteed, that the sum of n for all test cases does not exceed 4⋅105.
Output Print the answers for each test case in the following format:
You should print two integers, the minimum possible value of m and an integer k (0≤k≤109) that makes the maximum absolute difference between adjacent elements in the array a equal to m.
Make sure that after replacing all the missing elements with k, the maximum absolute difference between adjacent elements becomes m.
If there is more than one possible k, you can print any of them.
翻译 黑暗将要参加Motarack的生日。Dark决定给Motarack的礼物是一个数组a,包含n个非负整数。黑暗1000年前创造了那个数组,所以那个数组中的一些元素消失了。Dark知道Motarack不喜欢看到一个数组中有两个相邻的元素,而且它们之间的绝对差异很大。他没有太多的时间所以他想选择一个整数k (0 k 109)和替换所有缺失的元素数组中k。让米是所有相邻元素之间的最大绝对差(即|哀哀的最大值为所有1我n + 1 | 1)数组中的一个天黑后替换所有缺失的元素k。黑暗应该选择一个整数k m是最小化。你能帮助他吗?
输入
输入由多个测试用例组成。第一行包含一个整数t(1≤t≤104)——测试用例的数量。测试用例的描述如下。 每个测试用例的第一行包含一个整数n(2≤n≤105)——数组a的大小。 每个测试用例的第二行包含n个整数a1,a2,…,an(−1≤ai≤109)。如果ai= - 1,则第i个整数丢失。保证每个测试用例中至少缺少一个整数。 它保证,n的总和为所有测试用例不超过4⋅105。
输出
用以下格式打印每个测试用例的答案: 您应该打印两个整数,m的最小可能值和一个整数k(0≤k≤109),使数组中相邻元素之间的最大绝对差等于m。 确保用k替换所有缺失的元素后,相邻元素之间的最大绝对差为m。 如果有不止一个k,你可以打印任何一个。
例子 input 7 5 -1 10 -1 12 -1 5 -1 40 35 -1 35 6 -1 -1 9 -1 3 -1 2 -1 -1 2 0 -1 4 1 -1 3 -1 7 1 -1 7 5 2 -1 5
output 1 11 5 35 3 6 0 42 0 0 1 2 3 4
题意:你要找到一个k值替代所有数组里面所有的-1使得相邻元素间的最大差值最小。
思路:其实这个题一上去可能拿着没什么思路,就容易发呆,但是的话你如果仔细思考,那么思路也会渐渐清晰,首先就是相邻的元素的绝对值差值,所以如果两个数都有的话,那么这个差值就是相减不会变,但如果一个存在,一个不存在的话,那么就是需要咱们找到一个值来替代了,所以首先我们遍历数组然后找到所有的存在一个数跟不存在一个数的那对相邻的数,然后的话我们将存在的数存起来,因为不存在的数大小都一致,那么我们思考如何使得差值尽可能的小呢?!,就是对数组B我们排序得到最大值跟最小值的平均值,用这个来代替数组中所有的-1,然后就是遍历不断更新相邻元素的最大差值,最后输出即可。
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const ll maxn = 2e5 + 13;
const ll mod = 1e9 + 7;
ll a[maxn];
ll n,m;
ll b[maxn];
int main(){
cin>>n;
while(n--)
{
cin>>m;
int flag=0;
ll sum=0;
ll mid=0;
for (ll i=1;i<=m;i++) cin >> a[i];
for (ll i=1;i<=m;i++){
if(i && a[i-1] == -1 && a[i] != -1)
b[flag++] = a[i];
else if(i<m && a[i+1] == -1 && a[i] != -1)
b[flag++] = a[i];
}
if (!flag){
cout <<0<<" "<<0<< endl;
continue;
}
sort(b, b+flag);
ll res=(b[0]+b[flag-1])/2;
ll ans = -1;
for (ll i=1;i<m;i++){
ll x=a[i];
ll y=a[i + 1];
if (x == -1) x=res;
if(y == -1) y=res;
ans = max(ans, abs(x-y));
}
cout<<ans<<" "<<res<<endl;
}
return 0;
}
C 题目我就不复制了,最近CF网站有点… 题意:就是给你一个01串的长度跟1的数目,然后顺序是你自己排的,求最多的含1的字串的数量
思路:一开始我就只从正面想着如何安置1的位置好让得含1的区间 最多的一回事了。但看榜单有些大佬3,4分钟就A了,想着难道是有什么规律???观察半天样例来了一个规律,但是我构造数据检验完全行不通!!
思路2:从反面思考,求含最多的1的区间,那么我们求出所有的总的区间数量,然后我们减去只有0的区间不就行了。那么m个1可以分成m+1个区间,就是把1当作隔板,隔板两侧都是0。(把0尽量平均分给m个1),然后用0的数量除以(m+1)得到区间数,在取余得到多余的数然后将这些数在平均分给余数个区间,然后由余数个区间是比原来区间多一个数,然后就对这两类区间求其总和减去就行了…(说的不太清楚-。。-)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100014;
ll t;
ll n,m;
int main(){
cin>>t;
while(t--){
cin>>n>>m;
ll res=n-m;// 0的个数
ll ans=(n+1)*n/2-((((res/(m+1))+1)*(res/(m+1))/2)*(m+1-(res%(m+1))))-((((res/(m+1))+2)*((res/(m+1))+1)/2)*(res%(m+1)));
cout<<ans<<endl;
}
return 0;
}
D
题意:没看怎么明白,晚上晕乎乎~
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, char>> ans;
int n, m, k, cur;
void add(int f, char c)
{
if (f == 0 || cur == k)
return;
f = min(f, k - cur);
ans.push_back({f, c});
cur += f;
}
int main()
{
scanf("%d%d%d", &n, &m, &k);
cur = 0;
add(n-1, 'D');
for(int j = 1; j < m; ++j)
{
add(1, 'R');
add(n-1, 'U');
add(n-1, 'D');
}
add(m-1, 'L');
for(int i = n-1; i >= 1; --i)
{
add(1, 'U');
add(m-1, 'R');
add(m-1, 'L');
}
if (cur < k)
{
puts("NO");
}
else
{
puts("YES");
printf("%dn", ans.size());
for(auto e: ans)
printf("%d %cn", e.first, e.second);
}
return 0;
}
- Linux 系统安全与优化配置
- Extjs 项目中常用的小技巧,也许你用得着(2)
- 这或许是对小白最友好的python入门了吧——16,输入文本
- Extjs 项目中常用的小技巧,也许你用得着(1)
- Extjs4.2+webAPI+EF实现分页以及webapi的数据传值
- 【实践操作】 在iOS11中使用Core ML 和TensorFlow对手势进行智能识别
- 这或许是对小白最友好的python入门了吧——15,嵌套
- C#新功能--命名参数与可选参数
- 这或许是对小白最友好的python入门了吧——14,遍历字典
- C#新功能--命名参数
- Tomcat 安全配置与性能优化
- 【机器学习】伪标签(Pseudo-Labelling)的介绍:一种半监督机器学习技术
- 这或许是对小白最友好的python入门了吧——13,字典初识
- PHP 安全与性能
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Android Studio引入FFmpeg的方法
- Android Studio 中获取屏幕宽度实例
- Android studio 生成带Kotlin文档的实现方式
- 基于Android FileProvider 属性配置详解及FileProvider多节点问题
- Android 通过API获取数据库中的图片文件方式
- android尺子的自定义view——RulerView详解
- 浅谈Android Studio3.6 更新功能
- Android 自定义View手写签名并保存图片功能
- android 使用Xml文件定义Shape方式
- Android 判断所有字段是否已经输入的实例
- Android 将网络的Url资源转换为Drawable资源方式
- Android实现动态改变shape.xml中图形的颜色
- 解决android.support.v4.content.FileProvide找不到的问题
- 为Android系统添加config.xml 新配置的设置
- 浅析Android录屏 MediaRecorder