A

题意:问你恰好修改一个字符,能不能使得字符串变成回文串

题解:显然直接for一遍,如果长度为偶数,那么不一样的必须是1个;如果长度为奇数,那么不一样的也可以是0个

#include<bits/stdc++.h>
using namespace std; string s;
int main(){
cin>>s;
int tmp = 0;
for(int i=0;i<s.size();i++){
if(s[i]!=s[s.size()-1-i])
tmp++;
}
if(tmp>2||(tmp==0&&s.size()%2==0)){
cout<<"NO"<<endl;
}else{
cout<<"YES"<<endl;
}
}

B - Mike and strings

题意:你可以把开头的字符移动到最后去,然后问你最少一共移动多少次,可以使得所有字符都变得一模一样。

题解:显然就直接暴力就好了嘛,数据范围很小。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7; string s[maxn];
int n;
int main(){
cin>>n;
int ans = 1e5+7;
for(int i=0;i<n;i++)
cin>>s[i];
for(int i=0;i<s[0].size();i++){
int tmp = i;
string s2 = s[0].substr(i,s[0].size()-i)+s[0].substr(0,i);
for(int j=1;j<n;j++){
int flag = 0;
for(int k=0;k<s[j].size();k++){
string s3 = s[j].substr(k,s[j].size()-k)+s[j].substr(0,k);
if(s3==s2){
flag = 1;
tmp+=k;
break;
}
}
if(flag == 0){
return puts("-1");
}
}
ans = min(ans,tmp);
}
cout<<ans<<endl;
}

C. Mike and gcd problem

题意:你可以操作(i,i+1)使得,a[i],a[i+1]变成a[i]-a[i+1]和a[i]+a[i+1],问你最少操作多少次,可以使得所有数的gcd>1

题解:如果一开始不行的话,那么我们就让gcd等于2就好了,那么就让所有数都变成偶数,如果两个数都是奇数,那么一次就变成了。如果是奇数和偶数,那么得两次。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n,a[maxn];
int gcd(int a,int b){
if(b==0)return a;
return gcd(b,a%b);
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++)
cin>>a[i];
int tmp = 0;
for(int i=0;i<n;i++){
tmp = gcd(a[i],tmp);
}
if(tmp>1){
cout<<"YES"<<endl;
cout<<"0"<<endl;
return 0;
}
int ans = 0;
for(int i=0;i<n;i++){
if(a[i]%2==1){
if(a[i+1]%2==1){
ans++;
}else
ans+=2;
a[i]=0,a[i+1]=0;
}
}
cout<<"YES"<<endl;
cout<<ans<<endl;
}

D. Mike and distribution

题意:让你选出最多n/2+1个数,出来要求2A[i]和2B[i]都大于数组的和。

题解:显然我们先排序,然后我们两两对比,我们当然是选择第二大的就好了。证明很简单,这里略过。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
pair<int,pair<int,int> >a[maxn];
int n;
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i].first),a[i].second.second = i+1;
for(int i=0;i<n;i++)
scanf("%d",&a[i].second.first);
cout<<n/2+1<<endl;
sort(a,a+n);
cout<<a[n-1].second.second<<" ";
for(int i=n-2;i>=0;i-=2){
if(i==0){
cout<<a[i].second.second<<endl;
}else{
if(a[i].second.first>a[i-1].second.first)
cout<<a[i].second.second<<" ";
else
cout<<a[i-1].second.second<<" ";
}
}
}

Codeforces Round #410 (Div. 2) 题解 【ABCD】的更多相关文章

  1. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  2. Codeforces Round #410 (Div. 2)

    Codeforces Round #410 (Div. 2) A B略..A没判本来就是回文WA了一次gg C.Mike and gcd problem 题意:一个序列每次可以把\(a_i, a_{i ...

  3. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  4. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  5. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  6. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  7. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  8. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  9. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

随机推荐

  1. Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 inconsistent binding

    1.发生原因  springAOP 里面绑定参数出现错误  核对绑定参数的名称    核对 springAOP的版本 2.aop切面表达式写的有误

  2. PYTHON-函数的定义与调用,返回值,和参数

    函数基础'''1. 什么是函数 具备某一功能的工具->函数 事先准备工具的过程--->函数的定义 遇到应用场景,拿来就用---->函数的调用 函数分类两大类: 1. 内置函数 2. ...

  3. rownum和分析函数 over

    select rownum, t.* from qyuser.tr_apply_info t where rownum < 10; --rownum 对于满足 查询条件的结果,从1 开始,所以大 ...

  4. ThinkPHP中如何获取指定日期后工作日的具体日期

    思路: 1.获取到查询年份内所有工作日数据数组2.获取到查询开始日期在工作日的索引3.计算需查询日期索引4.获得查询日期 /*创建日期类型记录表格*/ CREATE TABLE `tb_workday ...

  5. pytest七:assert断言

    断言是写自动化测试基本最重要的一步,一个用例没有断言,就失去了自动化测试的意义了.什么是断言呢?简单来讲就是实际结果和期望结果去对比,符合预期那就测试 pass,不符合预期那就测试 failed py ...

  6. 【C++】拷贝构造函数(深拷贝,浅拷贝)详解

    一.什么是拷贝构造函数  首先对于普通类型的对象来说,它们之间的复制是很简单的,例如: ; int b = a; 而类对象与普通对象不同,类对象内部结构一般较为复杂,存在各种成员变量. 下面看一个类对 ...

  7. CSS3滚动条美化,CSS3滚动条皮肤

    CSS3 -webkit-scrollbar滚动条皮肤美化实现,利用-webkit-scrollbar,-webkit-scrollbar-track,-webkit-scrollbar-thumb这 ...

  8. BZOJ4974 八月月赛 Problem D 字符串大师 KMP

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ4974 - 八月月赛 Problem D 题意概括 一个串T是S的循环节,当且仅当存在正整数k,使得 ...

  9. 【Java】 剑指offer(45) 把数组排成最小的数

    本文参考自<剑指offer>一书,代码采用Java语言. 更多:<剑指Offer>Java实现合集   题目 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接 ...

  10. 试安装pyQt5+eric6+python安装

    1.先安装pip最新版 安装之前把sit-packages----pip旧版本删掉 然后再cmd输入pip install --user update pip 2.安装pyqt5 pip instal ...