Educational Codeforces Round 49 (Rated for Div. 2)A到C题
A题意
给你t表示有t组测试数据,每组数据给你一个含小写字母的字符串,每个字符必须变为它相邻的字符,问最后是否能变成回文串。a不能变成z,反过来也不行
分析
只需对对称位置判断差是否小于2且不等于1,因为等于1无论怎么变都不行
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
int i,n;
string s;
//freopen("in.txt","r",stdin);
while(cin>>t){
while(t--){
cin>>n>>s;
bool flag=1;
for(i=0;i<n/2;i++){
if(abs(int(s[i]-s[n-(i+1)]))>2||abs(int(s[i]-s[n-(i+1)]))==1)
{
flag=0;
break;
}
}
if(flag) cout<<"YES\n";
else cout<<"NO\n";
}
}
return 0;
}
B题题意


分析
找规律,也不知道怎么说了,注意n奇偶问题
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n,q,x,y;
//freopen("in.txt","r",stdin);
while(cin>>n>>q){
while(q--){
cin>>x>>y;
ll ans=0;
if((x+y)&1){
ans+=(n*n+1)/2;
ans+=(y+1)/2;
ans+=(x-1)/2*n;
if(x%2==0) ans+=n/2;
}
else {
ans+=(y+1)/2;
ans+=(x-1)/2*n;
if(x%2==0) ans+=(n+1)/2;//巧妙处理奇偶问题,很关键
}
cout<<ans<<endl;
}
}
return 0;
}
C题题意
给你n个数让你选四个数使构成矩形,使得P*P/S最小,P是周长,S是面积
分析
假设选的是a a b b 那么PP/S==8+4(b/a+a/b)很容易知道当a和b很“近”时,即(b-a)/a越小结果越小
细节就是两两取相等的数,并用另一个数组存c起来,最后排序c,往后比较就好了
还要注意数组清0不要用memset,容易TLE
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[1000010],b[1000010],c[1000010];
int main(){
int n,t;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("in.txt","r",stdin);
cin>>t;
while(t--){
cin>>n;
int h=0,k;
for(int i=0;i<n;i++)
{
cin>>a[i];
b[a[i]]++;
if(b[a[i]]==2) c[h++]=a[i],b[a[i]]=0;
}
for(int i=0;i<n;i++) b[a[i]]=0;//注意清0,不要用memset
sort(c,c+h);
double ans=99999;
for(int i=1;i<h;i++)
{
if((c[i]-c[i-1])*1.0/c[i-1]<ans){
k=i;
ans=(c[i]-c[i-1])*1.0/c[i-1];
}
}
cout<<c[k]<<' '<<c[k]<<' '<<c[k-1]<<' '<<c[k-1]<<' '<<endl;
}
return 0;
}
Educational Codeforces Round 49 (Rated for Div. 2)A到C题的更多相关文章
- Educational Codeforces Round 53 (Rated for Div. 2) (前五题题解)
这场比赛没有打,后来补了一下,第五题数位dp好不容易才搞出来(我太菜啊). 比赛传送门:http://codeforces.com/contest/1073 A. Diverse Substring ...
- 【Educational Codeforces Round 49 (Rated for Div. 2) 】
A:https://www.cnblogs.com/myx12345/p/9843826.html B:https://www.cnblogs.com/myx12345/p/9843869.html ...
- Educational Codeforces Round 49 (Rated for Div. 2)
题目链接 还缺F和G,至少上橙之后把F补了吧. A - Palindromic Twist 题意:每个字母恰好操作一次,变成其之前或者其之后的一个字母,注意'a'和'z'不互通,求是否可以变成回文串. ...
- Educational Codeforces Round 58 (Rated for Div. 2) (前两题题解)
感慨 这次比较昏迷最近算法有点飘,都在玩pygame...做出第一题让人hack了,第二题还昏迷想错了 A Minimum Integer(数学) 水题,上来就能做出来但是让人hack成了tle,所以 ...
- Educational Codeforces Round 57 (Rated for Div. 2) 前三个题补题
感慨 最终就做出来一个题,第二题差一点公式想错了,又是一波掉分,不过我相信我一定能爬上去的 A Find Divisible(思维) 上来就T了,后来直接想到了题解的O(1)解法,直接输出左边界和左边 ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
随机推荐
- k-vim安装及The ycmd server SHUT DOWN (restart with ':YcmRestartServer')这种错误的解决方法
vim配置 下载地址:https://github.com/wklken/k-vim 安装步骤: 1. clone 到本地 git clone https://github.com/wklken/k- ...
- Django框架的使用教程--站点的管理[七]
Django的站点管理 创建超级管理员命令(密码要8位) python manage.py createsuperuser 进入站点管理 注册模型类 from django.contrib impor ...
- 使用navicat 连接mysql出现1251错误
最近需要用MYSQL,使用navicat 连接时总出现1251错误,在网上查了一些别人的方法并试过 以下方法是正确的. 方法来自:https://blog.csdn.net/XDMFC/article ...
- ELK-elasticsearch-6.3.2部署
参考博客:linux下ElasticSearch.6.2.2集群安装与head.Kibana.X-Pack..插件的配置安装 参考博客:ELK5.5.1 插件安装实践纪要(head/bigdesk/k ...
- VMware安装CentOS6
1. 搭建虚拟化环境常见故障讲解 2. 安装CentOS Linux系统 ……………… PS:运维老鸟教你安装centos6.5如何选择安装包 3. 远程连接LInux ip配置 注意:不用做任何修改 ...
- Unity琐碎(1) 编辑器参数修改
今天在写编辑器面板的时候,突然发现如果面板参数变化的时候,不能实时修改表现效果(参数没有生效). public int monsterCount ; void Awake() { monsterCou ...
- IntelliJ IDEA 项目结构旁边出现 0%classes,0% lines covered
不知道一不小心点到哪里,项目变成如下形式 使用ctrl + Alt + F6弹出如下框,取消勾选-->点击Show Selected就可以去掉了 官网解释
- Bash On Windows上安装JDK
1. 引言 由于实习生转正,公司给配了一台新电脑,配置不用多说,16G内存,i7-7700的CPU,128SSD的系统盘,1T的机械硬盘,虽然只有一个破核显.对于我个人而言,最重要的是系统从Windo ...
- 解决jqueryeasyUI dialog 弹出窗体超出浏览器,导致不能关闭的bug
使用panel的onMove事件攻克了panel,dialog以及window组件在被拖动时,会超出浏览器边界而无法拖回的情况. 当窗体被拖出浏览器有边界时.$(document).width();会 ...
- JVM解释器和编译器
首先看一个命令 [root@insure ~]# java -version java version "1.8.0_191" Java(TM) SE Runtime Enviro ...