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数... 子串的定义..是从这列数中选出的数..只要序号不同 ...
随机推荐
- mysql_jdbc
package com.lovo.day18_jdbc1; import java.sql.Connection; import java.sql.DriverManager; import java ...
- OJ刷题---猜算式
题目要求: 输入代码: #include<iostream> using namespace std; void Calc(); int main() { Calc(); return 0 ...
- OpenLayers3基础教程——OL3之Popup
概述: 本节重点讲述OpenLayers3中Popup的调用时实现,OL3改用Overlay取代OL2的Popup功能. 接口简单介绍: overlay跟ol.control.Control一样,是一 ...
- idle-实现清屏
最近在学习python的时候,需要用到ubuntu的python idle.这个工具可以测试python语法.但是呢,在使用的过程中遇到了一个问题.就是随着你的输入,你会发现这个输入会停留在这个界面的 ...
- LA 2531 The K-league 最大流
#include <iostream> #include <cstdio> #include <fstream> #include <algorithm> ...
- [AngularFire2 & Firestore] Example for collection and doc
import {Injectable} from '@angular/core'; import {Skill} from '../models/skills'; import {AuthServic ...
- HDOJ 5357 Easy Sequence DP
a[i] 表示以i字符开头的合法序列有多少个 b[i] 表示以i字符结尾的合法序列有多少个 up表示上一层的'('的相应位置 mt[i] i匹配的相应位置 c[i] 包括i字符的合法序列个数 c[i ...
- HTML5的设计目的是为了在移动设备上支持多媒体
HTML5的设计目的是为了在移动设备上支持多媒体
- JAVA 多线程和进程概念的引入
1.并发和并行 并行:指两个或多个时间在同一时刻发生(同时发生): 并发:指两个或多个事件在一个时间段内发生. 在操作系统中,安装了多个程序,并发指的是在一段时间内宏观上有多个程序同时运行,这在单 C ...
- Xcode7 的两个小坑
Xcode7 还在 beta.时不时崩一下什么的倒也是预料之中的事.没料到的是之前用着好好的,今天升完 El Capitan 之后,模拟器竟然不见了,设备倒是在 schema 栏右边里能看到.只是注明 ...