Codeforces 145A-Lucky Conversion(规律)
2 seconds
256 megabytes
standard input
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.
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.
Print on the single line the single number — the minimum number of operations needed to convert string ainto string b.
47
74
1
774
744
1
777
444
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(规律)的更多相关文章
- Lucky Conversion(找规律)
Description Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive int ...
- CodeForces 146A Lucky Ticket
Lucky Ticket Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submi ...
- codeforces D. Queue 找规律+递推
题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...
- Codeforces 626B Cards(模拟+规律)
B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...
- Codeforces 121A Lucky Sum
Lucky Sum Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origi ...
- codeforces 630 I(规律&&组合)
I - Parking Lot Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- codeforces 630C Lucky Numbers
C. Lucky Numbers time limit per test 0.5 seconds memory limit per test 64 megabytes input standard i ...
- 数据结构(线段树):CodeForces 145E Lucky Queries
E. Lucky Queries time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...
- CodeForces 146E - Lucky Subsequence DP+扩展欧几里德求逆元
题意: 一个数只含有4,7就是lucky数...现在有一串长度为n的数...问这列数有多少个长度为k子串..这些子串不含两个相同的lucky数... 子串的定义..是从这列数中选出的数..只要序号不同 ...
随机推荐
- Android资源推荐
Intellj IDEA 安装配置 使用IntelliJ IDEA 13搭建Android集成开发环境(图文教程) Android设计指南站点 图标 App Icon Template免费的Photo ...
- USACO milk
/* ID:kevin_s1 PROG:milk LANG:C++ */ #include <iostream> #include <string> #include < ...
- 69.类型后缀,重载操作符""
#include <iostream> using namespace std; class myclass { public: int num; int num2; public: my ...
- CDQZ 0003:jubeeeeeat
0003:jubeeeeeat 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 256000kB 描述 众所周知,LZF很喜欢打一个叫Jubeat的游戏.这是个音乐游戏,游戏界面是 ...
- geotif格式的波段描述信息探究
作者:朱金灿 来源:http://blog.csdn.net/clever101 有时打开一些geotif文件,可以看到它的波段描述,但是它究竟存储在文件的什么位置呢?今天研究了一下,大致搞清了这个问 ...
- mac: brew的删除
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)" ...
- __get__()方法研究
看源码的时候发现了这个魔法方法 class A(object): def __init__(self): self.name = 'mod' def __get__(self, instance, o ...
- 今日SGU 5.10
SGU 168 题意:从a矩阵求出b矩阵,规则直接看题目就行了,不好打字说明 收获:dp #include<bits/stdc++.h> #define de(x) cout<< ...
- spring mvc 接收ajax 复杂结构数据
1. 前段将要发送的信息转换成json字符串 2. spring mvc 使用 @RequestBody 来接收字符串,然后解析
- 关于Blocking IO,non-Blokcing IO,async IO的区别和理解
来源:http://shmilyaw-hotmail-com.iteye.com/blog/1896683 概括来说,一个IO操作可以分为两个部分:发出请求.结果完成.如果从发出请求到结果返回,一直B ...