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& ...
随机推荐
- 传智播客张孝祥java邮件开发随笔01
01_传智播客张孝祥java邮件开发_课程价值与目标介绍 02_传智播客张孝祥java邮件开发_邮件方面的基本常识 03_传智播客张孝祥java邮件开发_手工体验smtp和pop3协议 第3课时 关于 ...
- python+mongodb+flask的基本使用
最近在做一个设备管理系统的后端,需要用python结合mongodb来实现,查了一下flask框架是比较合适的,自己摸索了好久一步步慢慢实现基本功能. 在程序开始之前请确保mongodb服务是开启的, ...
- 2.2Python数据处理篇之---math模块的数学函数
目录 目录 前言 (一)一览表 1.基本函数 2.对数函数 3.三角函数 4.角度的切换 5.双曲函数 6.math定义的常数 (二)实例 目录 前言 math模块是基础的python数学函数模块,是 ...
- apply 和call 的区别,apply实用小技巧
Js apply方法详解 我在一开始看到javascript的函数apply和call时,非常的模糊,看也看不懂,最近在网上看到一些文章对apply方法和call的一些示例,总算是看的有点眉目了,在这 ...
- 网络流(四)dinic算法
传送门: 网络流(一)基础知识篇 网络流(二)最大流的增广路算法 网络流(三)最大流最小割定理 网络流(四)dinic算法 网络流(五)有上下限的最大流 网络流(六)最小费用最大流问题 转自:http ...
- Python中的 redis keyspace 通知
介绍 Redis是内存中的数据结构存储,用于缓存.高速数据摄取.处理消息队列.分布式锁定等等. 与其他内存存储相比,使用Redis的优势在于它提供了持久性和数据结构,比如列表.集合.排序集合和散列. ...
- BZOJ4170:极光(CDQ分治)
Description "若是万一琪露诺(俗称rhl)进行攻击,什么都好,冷静地回答她的问题来吸引她.对方表现出兴趣的话,那就慢慢地反问.在她考虑答案的时候,趁机逃吧.就算是很简单的问题,她 ...
- 转://对于11gR2的集群relink
对于11gR2的集群relink参考MOS:Do I need to relink the Oracle Clusterware / Grid Infrastructure home after an ...
- mysql索引优化-order/group
为排序使用索引 KEY a_b_c (a,b,c) order by 能使用索引最左前缀 -order by a -order by a,b -order by a,b,c -order by a d ...
- (1) 天猫精灵接入Home Assistant- 网站论坛
https://bbs.hassbian.com/forum-38-1.html 1051196347 123456 https://bbs.hassbian.com/thread-4054-1-1. ...