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所有的 ...
随机推荐
- Windows驱动开发-内核常用内存函数
搞内存常用函数 C语言 内核 malloc ExAllocatePool memset RtlFillMemory memcpy RtlMoveMemory free ExFreePool
- C++面试常见问题——17类模板的使用
类模板的使用 注意在每次类模板函数时都需要声明一个类模板 #include<iostream> using namespace std; template <class T,int ...
- VUE - 取消默认事件
1,在 methods 中 <template> <div> <form @submit="addTodo"> ...
- C++编程学习(十一) 指针和引用的区别
1.指针有自己的一块空间,而引用只是一个别名: 2.使用sizeof看一个指针的大小是4,而引用则是被引用对象的大小: 3.指针可以被初始化为NULL,而引用必须被初始化且必须是一个已有对象 的引用: ...
- dwr超时
DWR可以指定超时设置: 1.设置局部超时: RemoteBean.remoteMethod(param1, param2, ..., { callback: callbackfun, //回调函数 ...
- 吴裕雄--天生自然java开发常用类库学习笔记:正则表达式
public class RegexDemo01{ public static void main(String args[]){ String str = "1234567890" ...
- Windows按键消息—虚拟键码(转)
源地址:http://c.biancheng.net/cpp/html/1253.html 虚拟键码保存在WM_KEYDOWN.WM_KEYUP.WM_SYSKEYDOWN和WM_SYSKEYUP消息 ...
- vCenter组件和服务
1).随VMware Platform Services Controller一起安装的服务 a. vCenter Single Sign-On身份验证服务 b. vSphere 许可证服务 c. V ...
- 使用pip install jupyter报错处理办法及修改Jupyter默认加载路径的方法
1.配置python环境之后想使用Jupyter,网上查看可以使用pip install Jupyter安装,执行命令行后正常安装,安装到一半以后报错,如图1.2 图1 图2 2.发现是安装过程中安装 ...
- python 输出六行星号✳
for i in range(1,6): for j in range(5-i): print(" ",end=" ") for j in range(1,2* ...