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]代表左端点 ...
随机推荐
- Spring Boot进阶系列四
这边文章主要实战如何使用Mybatis以及整合Redis缓存,数据第一次读取从数据库,后续的访问则从缓存中读取数据. 1.0 Mybatis MyBatis 是支持定制化 SQL.存储过程以及高级映射 ...
- Redis读写分离技术解析
背景 云数据库Redis版不管主从版还是集群规格,replica作为备库不对外提供服务,只有在发生HA的时候,replica提升为master后才承担读写流量.这种架构读写请求都在master上完成, ...
- go 优秀文档
go语言资料汇总 : https://blog.zhnytech.com/articles/2016/07/15/Golang%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99% ...
- 【转】JavaScript 高性能数组去重
原文地址:https://www.cnblogs.com/wisewrong/p/9642264.html 一.测试模版 数组去重是一个老生常谈的问题,网上流传着有各种各样的解法 为了测试这些解法的性 ...
- spring boot 从开发到部署上线(简明版)
我们组有一个优良传统--借鉴于"冰桶挑战赛"的形式,采取点名的方式,促进团队成员每天利用一小段时间,不断的完善团队 wiki 的小游戏. 但有时候忙于业务,可能会忘记,所以我写了一 ...
- Spring通过注解获取所有被注解标注的Beans
Spring提供的方法:Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annot ...
- docker compose 编排
Compose是Docker的服务编排工具,主要用来构建基于Docker的复杂应用,Compose 通过一个配置文件来管理多个Docker容器,非常适合组合使用多个容器进行开发的场景. 说明:Comp ...
- 在Apache中安装php5.6 & php7.3
1.下载 httpd-2.4.41-win64-VC15.zip.php5.6 + vc11. php7.3 + vc14-16 2.配置httpd,在 httpd.conf L180 添加如下 ...
- cocos2d设置窗口标题
//窗口标题 #ifdef WIN32 CCEGLView* pGlView=CCDirector::sharedDirector()->getOpenGLView(); if (pGlView ...
- Mysql——查看数据库,表占用磁盘大小
.查询所有数据库占用磁盘空间大小 select TABLE_SCHEMA, concat(,),' MB') as data_size, concat(,),'MB') as index_size f ...