B2. Character Swap (Hard Version) This problem is different from the easy version. In this version Ujan makes at most 2…
B1. Character Swap (Easy Version) This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems. After struggling and failing many times, Ujan decided to tr…
题意:给定两个字符串,问是否存在交换方案使得两个字符串相同,方案为交换次数小于等于2n,且每次只交换s1与s2中的一个字符 题解:考虑从前往后枚举,当第i位不同时,考虑找后边的第j位,若存在这样的第j位,则存在方案 1.存在aj==ai且j>i,那么交换aj,bi 2.存在bj==ai且j>i,那么先交换aj,bj,在交换aj,bi 这样对于每个位置最多两次操作,故若存在方案则一定在2n次内交换完成 #include<iostream> #include<cstdio>…
题意:给你两个字符串,问是否存在交换方案使得两个字符串变成一样的,方案为只交换一次且只交换s1与s2里的一个字符 题解:若一开始就相同,则存在交换方案 若一开始不同的位置为1个或大于2个,则不存在方案 若一开始不同的位置为2个,则看ai==aj 或 bi==bj,只要满足其中一个就存在方案,否则不存在方案 #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #incl…
This problem is different from the easy version. In this version Ujan makes at most 2n2n swaps. In addition, k≤1000,n≤50k≤1000,n≤50 and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previou…
This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems. After struggling and failing many times, Ujan decided to try to clean up his house again. He…
链接: http://codeforces.com/contest/1243/problem/B2 题目大意: 两个字符串,判断能否通过交换为从而使得这两个字符串完全一致,如不可以的话,直接输出NO,可以的话输出YES,并且输出每一步的交换位置. 思路:如果没个字符出现的次数为偶数次的话,那么一定可以成功,否则的话一定是NO. 如果说S[i]!=T[i],假如说,S中有与T[i]相同的元素,那么直接交换就可以了,操作次数为1,在T中找S[i]操作相同. S中没有与T[i]相同的元素,我们保证了每…
传送门 •前置知识-multimap的用法 $multimap$ 与 $map$ 的区别在于一个 $key$ 可以对应几个值: 对于 $map$ 而言,一个 $key$ 只能对应一个值,并且按照 $key$ 升序排列: 而 $multimap$ 的一个 $key$ 可以对应多个值,并且按照 $key$ 升序排列: 但是,相同的 $key$ 对应的多个值按照插入的顺序排列,不会自动排序: 定义:$multimap<char ,int >f$ 插值 $f.insert(make\_pair('a'…
You are given an array of size N. How many distinct arrays can you generate by swapping two numbers for exactly once? The two selected numbers can be equal but their positions in the array must be different. Input The first line of the input contains…
题意:给你一个模式串\(t\),现在要在主串\(s\)中删除多个子串,使得得到的\(s\)的子序列依然包含\(t\),问能删除的最长子串长度. 题解:首先,我们不难想到,我们可以选择\(s\)头部到最右边的子序列的头部和最左边的子序列的尾部到\(s\)的尾部这两个子串,除去这两个子串,我们要找的最大子串一定在子序列的头部到尾部中,即子序列中两个相邻字符位置的间隔,那么很显然,我们想让相邻的字符之间相隔最大,所以问题也就转化成了:求模式串的相邻字符在主串中的最大间隔长度,最优的情况一定是最左的子序…