Codeforces 145A-Lucky Conversion(规律)
2014-09-28 21:06
197 查看
A. Lucky Conversion
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7.
For example, numbers 47, 744, 4 are lucky and 5, 17,467 are
not.
Petya has two strings a and b of the same length n.
The strings consist only of lucky digits. Petya can perform operations of two types:
replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4);
swap any pair of digits in string a.
Petya is interested in the minimum number of operations that are needed to make string a equal to string b.
Help him with the task.
Input
The first and the second line contains strings a and b,
correspondingly. Strings a and b have equal lengths
and contain only lucky digits. The strings are not empty, their length does not exceed 105.
Output
Print on the single line the single number — the minimum number of operations needed to convert string ainto string b.
Sample test(s)
input
output
input
output
input
output
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7.
For example, numbers 47, 744, 4 are lucky and 5, 17,467 are
not.
Petya has two strings a and b of the same length n.
The strings consist only of lucky digits. Petya can perform operations of two types:
replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4);
swap any pair of digits in string a.
Petya is interested in the minimum number of operations that are needed to make string a equal to string b.
Help him with the task.
Input
The first and the second line contains strings a and b,
correspondingly. Strings a and b have equal lengths
and contain only lucky digits. The strings are not empty, their length does not exceed 105.
Output
Print on the single line the single number — the minimum number of operations needed to convert string ainto string b.
Sample test(s)
input
47 74
output
1
input
774 744
output
1
input
777 444
output
3
不得不承认CF上的题确实质量很好,这题还是A题就卡了好一阵,思路很诡异。。
题意: 给出一串字符串,只包含数字4和7 然后再给出另一个字符串,同样是只包含4和7,长度相同,现在给定两种操作,①:改变a串某位上的数字;②:交换a串任意两位上的数字,求最小操作数 使得a==b
因为是要最小操作数,所以要尽可能的执行交换操作,所以 扫一遍a串,看它和b串的对应位置上的数字是不是相同,若不同,记下4和7不同的个数,其中最大数就是答案。
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <vector> using namespace std; #define LL long long const int maxn=100050; char s[maxn],t[maxn]; int main() { while(~scanf("%s%s",s,t)) { int len=strlen(s),cnt1=0,cnt2=0; for(int i=0;i<len;i++) { if(s[i]!=t[i]) { if(s[i]=='4') cnt1++; else cnt2++; } } printf("%d\n",max(cnt1,cnt2)); } return 0; }
相关文章推荐
- Codeforces 145A-Lucky Conversion(规律)
- CodeForces - 633B A Trivial Problem(找规律)
- CodeForces 633B A Trivial Problem(找规律)
- CodeForces - 376C Divisible by Seven(数论:同余定理)(找规律)
- CodeForces - 743C Vladik and fractions (构造 找规律)
- CodeForces - 848A From Y to Y (找规律)
- Codeforces 638A:Home Numbers(规律)
- Codeforces 492D Vanya and Computer Game 循环节找规律
- CodeForces - 668B Little Artem and Dance(规律题)
- Codeforces 608B 找规律
- Codeforces 626B Cards(模拟+规律)
- CodeForces - 617B Chocolate (规律)
- Codeforces--630D--Hexagons(规律)
- codeforces B - Ralph And His Magic Field 找规律
- Codeforces--618B--Guess the Permutation(规律)
- Codeforces 903A A - Hungry Student Problem 规律
- CodeForces - 633B A Trivial Problem(找规律)
- CodeForces - 376C Divisible by Seven(数论:同余定理)(找规律)
- Codeforces 785C Anton and Fairy Tale (规律+二分查找)
- Codeforces 368C:Sereja and Algorithm(规律)