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. 【可视化】DataV接入ECharts图表库 可视化利器强强联手

    DataV接入ECharts图表库 可视化利器强强联手 摘要: 两个扛把子级产品的结合,而且文末有彩蛋. DataV 数据可视化是搭建每年天猫双十一作战大屏的幕后功臣,ECharts 是广受数据可视化 ...

  2. java.net.ServerSocket 解析

    注:本文来自:简书:jianshu 作者:jijs链接:http://www.jianshu.com/p/7c0722a8b66f來源:简书著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...

  3. python+selenium十:基于原生selenium的二次封装

    from selenium import webdriverfrom selenium.webdriver.support.wait import WebDriverWaitfrom selenium ...

  4. Windows安装使用Openssl

    1.什么是openssl? 2.下载安装 三方下载地址 备用64位和32位下载地址 选择32位或者64位合适的版本下载,例如Win64OpenSSL_Light-1_0_2h.exe: 设置环境变量, ...

  5. TCP连接的3次握手和4次挥手

    TCP连接的3次握手和4次挥手笔记 三次握手 TCP(Transmission Control Protocol) 传输控制协议 TCP是主机对主机层的传输控制协议,提供可靠的连接服务,采用三次握手确 ...

  6. python 全栈开发,Day100(restful 接口,DRF组件,DRF跨域(cors组件))

    昨日内容回顾 1. 为什么要做前后端分离? - 前后端交给不同的人来编写,职责划分明确.方便快速开发 - 针对pc,手机,ipad,微信,支付宝... 使用同一个接口 2. 简述http协议? - 基 ...

  7. 2018-2019 2 20165203 《网络对抗技术》 Exp1 PC平台逆向破解

    2018-2019 2 20165203 <网络对抗技术> Exp1 PC平台逆向破解 实验要求 1.掌握NOP, JNE, JE, JMP, CMP汇编指令的机器码 2.掌握反汇编与十六 ...

  8. 简易图书管理系统(主要是jsp的练习)

    1:首先设计用户表和图书表,设计的字段和类型如下图所示 1.1:用户表user 1.2:图书表book 2:第二写实体类user.java和book.java package com.bie.po; ...

  9. Compoer的应用

    composer总结 composer常用命令 composer list 列出所有可用的命令composer init 初始化composer.json文件(就不劳我们自己费力创建啦),会要求输入一 ...

  10. MQ确认机制之事务机制----confirm串行

    一:介绍 1.说明原理 A:生产者将信道设置成confirm模式,一旦信道进到confirm模式,所有该信道上发布的消息都会被指派一个唯一的ID(从1开始). 一旦消息被投递到所有匹配的队列后,bro ...