Ugly Pairs CodeForces - 1156B
题目链接:https://vjudge.net/problem/CodeForces-1156B
题意:给定一串字符,相邻字符的ASCII码不能是相邻的数字,比如ABC,假设ASCII码为,99 100 101 ,
就是不符合题意的字符串,ACF,就可以。
思路:从相邻字符的ASCII码不能是相邻的数字,可以想到字符串之间ASCII码至少差2,然后发现
ACE...假设是奇数ASCII码,BDF是偶数ASCII码,那么我们不妨把他们分成两组,
奇数的字符,偶数的字符,那就简单了,我们可以直接先把奇数的输出,再把偶数的输出,那么字符串
之间相邻字符的ASCII码不能是相邻的数字就很好来解决了,下面字符串都转化为数字,列举一些情况
① 只有偶数
② 只有奇数
③ 1 3 5 7 2
④ 1 3 5 7 6
⑤ 1 3 2
⑥ 1 3 2 4
下面四种情况判定下就OK了,代码有呼应。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std; typedef long long LL;
#define inf (1LL << 25)
#define rep(i,j,k) for(int i = (j); i <= (k); i++)
#define rep__(i,j,k) for(int i = (j); i < (k); i++)
#define per(i,j,k) for(int i = (j); i >= (k); i--)
#define per__(i,j,k) for(int i = (j); i > (k); i--) int main(){ ios::sync_with_stdio(false);
cin.tie(); char str[];
vector<int> one;
vector<int> two; int T;
cin >> T;
while(T--){ cin >> str; one.clear(); //奇数
two.clear(); //偶数
int len = strlen(str) - ;
rep(i,,len){
int tmp = str[i] - 'a' + ;
//判奇偶
if(tmp & ) one.push_back(tmp);
else two.push_back(tmp);
} //排好序,方便比较
sort(one.begin(),one.end());
sort(two.begin(),two.end());
//只有偶数
if(one.size() == ){
rep(o,,(int)two.size() - ) cout << (char)('a' + two[o] - );
cout << endl;
}
//只有奇数
else if(two.size() == ){
rep(o,,(int)one.size() - ) cout << (char)('a' + one[o] - );
cout << endl;
}
else{
int End_b = two.size() - ;
int End_a = one.size() - ; //判断③④⑤⑥的情况
if(abs(two[] - one[End_a]) != ){
rep(o,,(int)one.size() - ) cout << (char)('a' + one[o] - );
rep(o,,(int)two.size() - ) cout << (char)('a' + two[o] - );
cout << endl;
}
else if(abs(two[End_b] - one[]) != ){
rep(o,,(int)two.size() - ) cout << (char)('a' + two[o] - );
rep(o,,(int)one.size() - ) cout << (char)('a' + one[o] - );
cout << endl;
}
else cout << "No answer" << endl; } } getchar(); getchar();
return ;
}
Ugly Pairs CodeForces - 1156B的更多相关文章
- Educational Codeforces Round 64 (Rated for Div. 2)题解
Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...
- Educational Codeforces Round 64 (Rated for Div. 2) A,B,C,D,E,F
比赛链接: https://codeforces.com/contest/1156 A. Inscribed Figures 题意: 给出$n(2\leq n\leq 100)$个数,只含有1,2,3 ...
- Educational Codeforces Round 64(ECR64)
Educational Codeforces Round 64 CodeForces 1156A 题意:1代表圆,2代表正三角形,3代表正方形.给一个只含1,2,3的数列a,ai+1内接在ai内,求总 ...
- Educational Codeforces Round 64 选做
感觉这场比赛题目质量挺高(A 全场最佳),难度也不小.虽然 unr 后就懒得打了. A. Inscribed Figures 题意 给你若干个图形,每个图形为三角形.圆形或正方形,第 \(i\) 个图 ...
- Codeforces Edu Round 64 A-D
A. Inscribed Figures 分类讨论打表即可. PS:这道题翻译有歧义. 这样稍微翻转一下,就可以是\(7\)个交点呀...(大概是我没看英文题干导致的惨案) #include < ...
- Educational Codeforces Round 10 C. Foe Pairs 水题
C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permu ...
- Codeforces Round #562 (Div. 2) B. Pairs
链接:https://codeforces.com/contest/1169/problem/B 题意: Toad Ivan has mm pairs of integers, each intege ...
- Codeforces 1404 D. Game of Pairs
Codeforces 1404 D.Game of Pairs 给定\(2n\)个数\(1,2,...,2n\),A 和 B 将进行交互,规则如下: A 需要将元素分成 n 组 \(\mathbf{p ...
- Codeforces 159D Palindrome pairs
http://codeforces.com/problemset/problem/159/D 题目大意: 给出一个字符串,求取这个字符串中互相不覆盖的两个回文子串的对数. 思路:num[i]代表左端点 ...
随机推荐
- elasticsearch 常用命令 一直红色 重启不稳定 不停的宕机
persistent (重启后设置也会存在) or transient (整个集群重启后会消失的设置). 查看集群状态和每个indices状态.搜索到red的,没用就删除 GET /_cluster/ ...
- Elasticsearch运维经验总结
Elasticsearch运维经验总结 2018年12月10日 16:38:41 运小白 阅读数 3811 版本说明:5.6.4(要严格注意ES及其插件.第三方工具的版本匹配关系) 系统负载:(日 ...
- 模型区分度衡量指标-KS值
1.KS值--学习器将正例和反例分开的能力,确定最好的“截断点” KS曲线和ROC曲线都用到了TPR,FPR.KS曲线是把TPR和FPR都作为纵坐标,而样本数作为横坐标.但是AUC只评价了模型的整体训 ...
- laravel如何引用外部文件
(1).首先在app\Http\routes.php中定义路由: 1 2 3 Route::get('view','ViewController@view'); Route::get('article ...
- Zhe Second Language——
You got things to do. Place to go. People to see. Futures to make. 我们还有事要做,有地儿要去,有人要见,有梦要实现. Remembe ...
- docker image 镜像导入导出
docker image save -o webv6.tar techcn/noble.web:v6docker image load -i webv6.tar -q
- 一个刚入行的BIOS工程师的自我简介
现在是北京时间2019年11月28日,大学毕业已经工作四个多月.说来也是奇怪,大学里面明明主修机械电子工程,几乎是纯机械方向,毕业之后的工作却与主修的课程毫无关系.因为对机械这一行业毫无兴趣,大学里面 ...
- FusionInsight大数据开发---MapReduce与YARN应用开发
MapReduce MapReduce的基本定义及过程 搭建开发环境 代码实例及运行程序 MapReduce开发接口介绍 1. MapReduce的基本定义及过程 MapReduce是面向大数据并行处 ...
- SpringBoot中使用@scheduled定时执行任务需要注意的坑
spring boot: 计划任务@ EnableScheduling和@Scheduled @Scheduled中的参数说明 @Scheduled(fixedRate=2000):上一次开始执行时间 ...
- 整理:WPF中应用附加事件制作可以绑定命令的其他事件
原文:整理:WPF中应用附加事件制作可以绑定命令的其他事件 目的:应用附加事件的方式定义可以绑定的事件,如MouseLeftButton.MouseDouble等等 一.定义属于Control的附加事 ...