CodeForces - 748B Santa Claus and Keyboard Check
题意:给定两个字符串a和b,问有多少种不同的字母组合对,使得将这些字母对替换字符串b后,可以变成字符串a。注意字母对彼此各不相同。
分析:vis[u]记录与u可形成关系的字母,若u与v不同,则形成字母对。若之后该关系被打破,则输出-1。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 1000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
char a[MAXN], b[MAXN];
const string s = "abcdefghijklmnopqrstuvwxyz";
map<char, int> mp;
int vis[30];
int ans[30];
void init(){
for(int i = 0; i < 26; ++i){
mp[s[i]] = i + 1;
}
}
int main(){
init();
while(scanf("%s%s", a, b) == 2){
memset(vis, 0, sizeof vis);
memset(ans, 0, sizeof ans);
int len = strlen(a);
int cnt = 0;
bool ok = true;
for(int i = 0; i < len; ++i){
int tmpa = mp[a[i]], tmpb = mp[b[i]];
if(!vis[tmpa] && !vis[tmpb]){
vis[tmpa] = tmpb;
vis[tmpb] = tmpa;
if(tmpa != tmpb){
ans[cnt++] = tmpa;
}
}
else if(vis[tmpa] != tmpb || vis[tmpb] != tmpa){
ok = false;
break;
}
}
if(!ok){
printf("-1\n");
}
else{
printf("%d\n", cnt);
for(int i = 0; i < cnt; ++i){
printf("%c %c\n", ans[i] + 'a' - 1, vis[ans[i]] + 'a' - 1);
}
}
}
return 0;
}
CodeForces - 748B Santa Claus and Keyboard Check的更多相关文章
- Codeforces 784B Santa Claus and Keyboard Check
题面: 传送门 B. Santa Claus and Keyboard Check Input file: standard input Output file: standard output Time ...
- Codeforces Round #389 Div.2 B. Santa Claus and Keyboard Check
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- B. Santa Claus and Keyboard Check 模拟
http://codeforces.com/contest/752/problem/B uuu yyu xy xx 注意变化了之后,检查一次前面已经变化过的就好.因为可能前面的满足,但是变了后不满足. ...
- codeforces 748E Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Codeforces 752C - Santa Claus and Robot - [简单思维题]
题目链接:http://codeforces.com/problemset/problem/752/C time limit per test 2 seconds memory limit per t ...
- Codeforces 748D Santa Claus and a Palindrome
雅礼集训期间我好像考完试就开始划水了啊 给出k个长度相同的字符串,每个串有一个权值,选出一些串连成一个回文串.使得选中的串的总权值最大. 如果选一个串,必须同时选一个对称的串.还有一个特殊情况是可以在 ...
- CodeForces 748C Santa Claus and Robot (思维)
题意:给定一个机器人的行走路线,求最少的点能使得机器人可以走这样的路线. 析:每次行走,记录一个方向向量,每次只有是相反方向时,才会增加一个点,最后再加上最后一个点即可. 代码如下: #pragma ...
- CodeForces - 748E Santa Claus and Tangerines(二分)
题意:将n个蛋糕分给k个人,要保证每个人都有蛋糕或蛋糕块,蛋糕可切, 1.若蛋糕值为偶数,那一次可切成对等的两块. 2.若蛋糕值为奇数,则切成的两块蛋糕其中一个比另一个蛋糕值多1. 3.若蛋糕值为1, ...
- CodeForces - 748D Santa Claus and a Palindrome (贪心+构造)
题意:给定k个长度为n的字符串,每个字符串有一个魅力值ai,在k个字符串中选取字符串组成回文串,使得组成的回文串魅力值最大. 分析: 1.若某字符串不是回文串a,但有与之对称的串b,将串a和串b所有的 ...
随机推荐
- 2.13 阶段实战 使用layui重构选课系统
一.说在前面 昨天 学习表单校验插件validate,并使用ajax 自定义校验规则 今天 使用layui重构选课系统 二.题目要求 1.项目需求: 本项目所开发的学生选课系统完成学校对学生 ...
- POJ 1027:The Same Game 较(chao)为(ji)复(ma)杂(fan)的模拟
The Same Game Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5168 Accepted: 1944 Des ...
- 2-10 就业课(2.0)-oozie:12、cm环境搭建的基础环境准备
8.clouderaManager5.14.0环境安装搭建 Cloudera Manager是cloudera公司提供的一种大数据的解决方案,可以通过ClouderaManager管理界面来对我们的集 ...
- 动态设置html根字体大小(随着设备屏幕的大小而变化,从而实现响应式)
代码如下:如果设置了根字体大小,font-size必须是rem var html =document.querySelector('html'); html.style.fontSize = docu ...
- Unbutu下装oracle
Ubuntu 16.04安装Oracle 11gR2入门教程图文详解 转自 https://www.linuxidc.com/Linux/2017-12/149797.htm 原文作 ...
- Day4 - I - Trucking HDU - 2962
A certain local trucking company would like to transport some goods on a cargo truck from one place ...
- maven项目添加配置文件
1. 在src/main/resources下新建param.properties 2. 在param.properties文件中添加 mqtt.host=tcp://127.0.0.1:1883 m ...
- NO11 SSH故障排查思路和netstat命令
本章知识相关考试:1.企业场景面试题:Linux系统如何优化?2.企业场景面试题:SSH服务连不上,如何排查?记住回答技巧: 1 ping 2 telnet 客户端ssh工具:SecureCRT,x ...
- LeetCode874 模拟行走机器人(简单模拟—Java之HashSet简单应用)
题目: 机器人在一个无限大小的网格上行走,从点 (0, 0) 处开始出发,面向北方.该机器人可以接收以下三种类型的命令: -2:向左转 90 度-1:向右转 90 度1 <= x <= 9 ...
- thinkphp调用sqlserver储存过程返回多个结果集
首先安装扩展 windows 分为两个步骤 找到对应自己PHP版本的pdo扩展,下载解压出来,并且在php.ini里面启用扩展,需要注意的问题是php版本以及是否为安全版本 下载 ODBC Drive ...