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]代表左端点 ...
随机推荐
- nginx配置文件解释
#全局配置 # For more information on configuration, see:# * Official English Documentation: http://nginx. ...
- 小端存储转大端存储 & 大端存储转小端存储
1.socket编程常用的相关函数:htons.htonl.ntohs.ntohl h:host n:network s:string l:long 2.基本数据类型,2字节,4字 ...
- Android Studio 之 Navigation【1.页面之间的切换】
1.创建 2个 Fragment ,下面两个include 不要勾 2.创建好 Fragment 后,打开layout中的 fragment.xml 文件,将里面默认的 textView 控件删除掉 ...
- 常用war包插件
<build> <resources> <resource> <directory>src/main/java</directory> &l ...
- Python3+Robot Framework+RIDE安装使用教程
一.说明 Python3----网上很多文章都是用Python2,Robot Framework的部分文档没更新也直接写着不支持Python3(如RIDE does not yet support P ...
- 转 Hystrix超时实现机制
HystrixCommand在执行的过程中如何探测超时,本篇主要对此进行介绍说明. 1.主入口:executeCommandAndObserve #com.netflix.hystrix.Abstra ...
- nginx php上传大小设置
来源:http://blog.51yip.com/apachenginx/1751.html
- Akka-CQRS(13)- SSL/TLS for gRPC and HTTPS:自签名证书产生和使用
到现在,我们已经完成了POS平台和前端的网络集成.不过,还是那句话:平台系统的网络安全是至关重要的.前一篇博客里我们尝试实现了gRPC ssl/tls网络连接,但测试时用的证书如何产生始终没有搞清楚. ...
- tkinter添加背景音乐
一.问题利用tkinter来写一个游戏,添加一个背景音乐提高可玩性. 二.解决1.安装pygame首先是利用pygame的一个播放流:[pip install pygame]来完成pygame的安装. ...
- [转] js async await 终极异步解决方案
阅读目录 回顾 Promise async await 字面理解 async.await 如何执行 await 操作符 总结 既然有了promise 为什么还要有async await ? 当然是pr ...