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题的更多相关文章

  1. Educational Codeforces Round 53 (Rated for Div. 2) (前五题题解)

    这场比赛没有打,后来补了一下,第五题数位dp好不容易才搞出来(我太菜啊). 比赛传送门:http://codeforces.com/contest/1073 A. Diverse Substring ...

  2. 【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 ...

  3. Educational Codeforces Round 49 (Rated for Div. 2)

    题目链接 还缺F和G,至少上橙之后把F补了吧. A - Palindromic Twist 题意:每个字母恰好操作一次,变成其之前或者其之后的一个字母,注意'a'和'z'不互通,求是否可以变成回文串. ...

  4. Educational Codeforces Round 58 (Rated for Div. 2) (前两题题解)

    感慨 这次比较昏迷最近算法有点飘,都在玩pygame...做出第一题让人hack了,第二题还昏迷想错了 A Minimum Integer(数学) 水题,上来就能做出来但是让人hack成了tle,所以 ...

  5. Educational Codeforces Round 57 (Rated for Div. 2) 前三个题补题

    感慨 最终就做出来一个题,第二题差一点公式想错了,又是一波掉分,不过我相信我一定能爬上去的 A Find Divisible(思维) 上来就T了,后来直接想到了题解的O(1)解法,直接输出左边界和左边 ...

  6. 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 ...

  7. 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 ...

  8. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  9. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

随机推荐

  1. Selenium 、WebDriver :Capability

    Selenium | WebDriver Capability 内容摘要: 1.WebDriver 通用配置 2.RemoteWebDriver特有配置 3.Grid特有配置 4.在使用特定浏览器时的 ...

  2. python分包写入文件,写入固定字节内容,当包达到指定大小时继续写入新文件

    第6行通过 for 循环控制生成 .log 文件的数量 第8行,如果该文件存在时先进行清空,然后再进行写入操作 第13行,将文件大小的单位转为MB 第14行,如果文件大小超过1MB时,跳出当前循环,重 ...

  3. java按行和列进行输出数据

    package debug; public class Demo9 { public static void main(String[] args) { //输出4行5列星星 //外循环控制行数 // ...

  4. python五十七课——正则表达式(元字符)

    1).匹配单个字符(数字.英文.其它) 符号位: []:表示一个字符位 [0123456789]:表示一位,取值范围:[0,9]之间的任何一个值 [0-9]:表示一位,取值范围:[0,9]之间的任何一 ...

  5. swift的调用约定

    swift的静态绑定 Swift Calling Convention @convention(swift) func foo(_ x:Int, y:Int) sil @foo : $(x:Int, ...

  6. mini2440裸机试炼之—RTC闹钟中断,节拍中断

    版权声明:博客地址:http://blog.csdn.net/muyang_ren.源代码能够在我的github上找看看 https://blog.csdn.net/muyang_ren/articl ...

  7. Smith Numbers POJ - 1142 (暴力+分治)

    题意:给定一个N,求一个大于N的最小的Smith Numbers,Smith Numbers是一个合数,且分解质因数之后上质因子每一位上的数字之和 等于 其本身每一位数字之和(别的博客偷的题意) 思路 ...

  8. Qt 编程指南 4 按钮

    1按钮类的控件 逐个解释一下各个用途:(1)按压按钮 QPushButton最基本的按钮,点击该按钮通常是通知程序进行一个操作,比如弹个窗.下一步.保存.退出等等,这是经常用到的,操作系统里的对话框里 ...

  9. 一点不懂到小白的linux系统运维经历分享

    进入运维行业刚不到二个年头, 刚刚从大白变成小白.都说it行业是青春的饭.但是运维行业可不这么认为.运维工程师便是经验技术的积累,经历的过的沟沟坑坑都会融入你的血液,成为你的智慧. 二年前接触linu ...

  10. Linux x64 -- 内核程序(驱动程序)读取任意进程数据实现

    四级页表结构 现在的64位Linux系统中,并没有使用全部的64位地址空间,而是使用其低48位,高16位并没有使用. 其中 39至47这9位用于索引PGD(page global directory) ...