CodeForces - 752B
CodeForces - 752B
https://vjudge.net/problem/597648/origin
简单模拟,主要是细节
特殊情况多考虑一下,看代码就行
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 100010
#define For(i,a,b) for(int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar() using namespace std;
char c1[N],c2[N];
int n,a[N],cnt;
bool b[N];
void in(int &x){
int y=;
char c=g();x=;
while(c<''||c>''){
if(c=='-')y=-;
c=g();
}
while(c<=''&&c>=''){
x=(x<<)+(x<<)+c-'';c=g();
}
x*=y;
}
void o(int x){
if(x<){
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
}
int main(){
cin>>(c1+)>>(c2+);
n=strlen(c1+);
For(i,,n){
if(c1[i]==c2[i]&&!a[(int)c1[i]]){
a[(int)c1[i]]=(int)c1[i];
}
else
if(c1[i]!=c2[i]&&!a[(int)c1[i]]&&!a[(int)c2[i]]){
a[(int)c1[i]]=(int)c2[i];
a[(int)c2[i]]=(int)c1[i];
cnt++;
}
else
if(c1[i]!=c2[i]&&(a[(int)c1[i]]!=(int)c2[i]||a[(int)c2[i]]!=(int)c1[i])){
o(-);
return ;
}
else
if(c1[i]==c2[i]&&a[(int)c1[i]]!=(int)c1[i]){
o(-);
return ;
}
}
o(cnt);p('\n');
For(i,,n){
if(c1[i]!=c2[i]&&!b[c1[i]]){
p(c1[i]);p(' ');p(c2[i]);p('\n');
b[c1[i]]=b[c2[i]]=;
}
}
return ;
}
CodeForces - 752B的更多相关文章
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
- CodeForces - 148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- Orika JavaBean映射工具探秘
Orika是一个简单.快速的JavaBean拷贝框架,Orika使用字节代码生成来创建具有最小开销的快速映射器. 关于: 作为开发人员,我们必须为业务问题提供解决方案,我们希望利用我们的时间来做真正重 ...
- thinkphp 跳转和重定向
页面跳转 在应用开发中,经常会遇到一些带有提示信息的跳转页面,例如操作成功或者操作错误页面,并且自动跳转到另外一个目标页面.系统的\Think\Controller类内置了两个跳转方法success和 ...
- 二分图建图,并查集求联通——二维等价性传递 cf1012B好题!
/* 模拟二分图:每个点作为一条边,连接的是一列和一行(抽象成一个点,列在左,行在右) 由题意得 a-b相连,a-c相连,b-d相连,那么d-c就不用再相连了 等价于把二分图变成联通的需要再加多少边 ...
- flink提交文件出现java.io.IOException:unable to close file because the last block does not have enough number of replicas异常
当提交已经打包好的jar包时候,控制台出现以下的错误.
- 实用的 atom 插件
推荐几款我喜欢的Atom插件 时间 2017-05-05 09:00:00 Hi Linux 原文 http://www.hi-linux.com/posts/28459.html 主题 Atom ...
- requests 返回 521
网页端抓数据免不了要跟JavaScript打交道,尤其是JS代码有混淆,对cookie做了手脚.找到cookie生成的地方要费一点时间. 那天碰到这样一个网页,用浏览器打开很正常.然而用request ...
- jquery 表单验证插件
其他: <form action=""> First name: <input type="text" name="FirstNam ...
- JS数组 了解成员数量(数组属性length) myarr.length
了解成员数量(数组属性length) 如果我们想知道数组的大小,只需引用数组的一个属性length.Length属性表示数组的长度,即数组中元素的个数. 语法: myarray.length; //获 ...
- mongodb 3.2 yaml 配置详解及范例
mongodb3.x版本后就是要yaml语法格式的配置文件,下面是yaml配置文件格式如下:官方yaml配置文件选项参考:https://docs.mongodb.org/manual/ ... #c ...
- 导入excel并进行数据提取
/** * @description: 导入excel并进行数据提取 * @param {type} * @return: */ Vue.prototype.$importExcel = functi ...