Divisibility by 25 CodeForces - 988E
You are given an integer nn from 11 to 10181018 without leading zeroes.
In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes.
What is the minimum number of moves you have to make to obtain a number that is divisible by 2525? Print -1 if it is impossible to obtain a number that is divisible by 2525.
Input
The first line contains an integer nn (1≤n≤10181≤n≤1018). It is guaranteed that the first (left) digit of the number nn is not a zero.
Output
If it is impossible to obtain a number that is divisible by 2525, print -1. Otherwise print the minimum number of moves required to obtain such number.
Note that you can swap only adjacent digits in the given number.
Examples
5071
4
705
1
1241367
-1
Note
In the first example one of the possible sequences of moves is 5071 →→ 5701 →→ 7501 →→ 7510 →→ 7150.
题意:一个大数,只能移动相邻的两位,问移动几次后可以除以25后没有余数
思路:一个模拟,末尾是00,25,50,75就可以了
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define INF 0x3f3f3f3f
const long long int maxn=2e5+;
string str;
int ans;
void solve(char a,char b)
{
string s=str;
int cnt1=s.rfind(a),cnt2=s.rfind(b);
if(a=='' && b=='')
cnt1=s.rfind(a,cnt1-);
if(cnt1==string::npos || cnt2==string::npos)
return ;
int cnt=;
if (cnt1 > cnt2)
{
cnt++;
swap(cnt1, cnt2);
}
for (int i = cnt2; i+ < s.size(); i++)
{
cnt++;
swap(s[i], s[i+]);
}
for (int i = cnt1; i+ < s.size()-; i++)
{
cnt++;
swap(s[i], s[i+]);
}
cnt += find_if(s.begin(), s.end(), [](char c){return c != '';}) - s.begin();
ans = min(ans, cnt);
} int main()
{
cin>>str;
ans=INF;
solve('','');
solve('','');
solve('','');
solve('','');
if(ans == INF)
ans=-;
cout<<ans<<endl;
return ;
}
Divisibility by 25 CodeForces - 988E的更多相关文章
- Divisibility by 25 CodeForces - 988E (技巧的暴力)
You are given an integer nn from 11 to 10181018 without leading zeroes. In one move you can swap any ...
- Divisibility by 25 CodeForces - 988E(模拟)
遇见模拟题 有两种做法 例如这题: 1.直接去算次数(统计哪个数在第几位,然后去运算) 2.模拟操作 贴一个别人的代码...https://blog.csdn.net/weixin_39453270/ ...
- Codeforces Round #486 (Div. 3) E. Divisibility by 25
Codeforces Round #486 (Div. 3) E. Divisibility by 25 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- CF 988E Divisibility by 25 思维 第十二
Divisibility by 25 time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces 988E. Divisibility by 25
解题思路: 只有尾数为25,50,75,00的数才可能是25的倍数. 对字符串做4次处理,以25为例. a. 将字符串中的最后一个5移到最后一位.计算交换次数.(如果没有找到5,则不可能凑出25,考虑 ...
- Codeforces Round #486 (Div. 3)988E. Divisibility by 25技巧暴力||更暴力的分类
传送门 题意:给定一个数,可以对其做交换相邻两个数字的操作.问最少要操作几步,使得可以被25整除. 思路:问题可以转化为,要做几次交换,使得末尾两个数为00或25,50,75: 自己一开始就是先for ...
- 题解 【Codeforces988E】Divisibility by 25
本题是数论好题! 首先我们需要了解一个关于数论的性质: 一个数只要后两位能被25(或4)整除,这个数就能被25(或4)整除. 同理,后三位:(或8).后四位:(或16)亦是如此. 所以,我们只需要判断 ...
- 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3
◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...
- Codeforces Round #306 (Div. 2) C. Divisibility by Eight 暴力
C. Divisibility by Eight Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
随机推荐
- SpringBoot---Web开发---Thymeleaf模板引擎
一.前言 1.JSP在内嵌的Servlet容器中运行有一些问题: 1.1 内嵌的Tomcat.Jetty不支持以jar形式运行JSP: 2.2 Undertow不支持JSP: 2.SpringBoot ...
- HATEOAS REST Service
用户通过点击页面的href的链接地址,而跳转到其他网页,实现浏览网页的过程了. -> 让调用REST的api就可以实现,类似于用户浏览网页的从一个页面跳转到另外一个页面的过程了 -> 而这 ...
- ef 操作 mysql 中文乱码问题
1.保证mysql数据的编码为utf8 启动mysql mysql -hlocalhost -uroot -p 输入密码 show VARIABLES like 'character_%'; SET ...
- marquee标签(跑马灯)
- 洛谷 P1203 [USACO1.1]坏掉的项链Broken Necklace
坏掉的项链Broken Necklace 难度:★ Code: #include <iostream> #include <cstdio> #include <cstri ...
- [Loading Component]Loading组件的v-model设计是否不合理?
vue在2.4.2版本中给computed里的属性加了限制,详见assigning to a computed property without setter does not fail 项目将vue ...
- OCX和DLL的区别
转自:http://blog.csdn.net/scucj/archive/2006/06/29/852181.aspx OCX和DLL的区别 一.关于DLL的介绍 DLL,动态链接库,Dy ...
- win10中使用win7/win8.1"个性化"
直接下载使用: 点此下载 设置 Windows Registry Editor Version 5.00 ; ; Created by http://winaero.com, reedited by ...
- code Gym 100500D T-shirts(暴力)
因为只能买一次,暴力枚举一下买的衣服的大小. #include<cstdio> #include<map> #include<algorithm> using na ...
- vue2使用animate css
先上几个链接 vue插件大集合:awesome-vue vue2插件: vue2-animate:vue2-animate vue2插件vue2-animateDEMO: vue2-animatede ...