Divisibility by 25 CodeForces - 988E(模拟)
遇见模拟题 有两种做法 例如这题:
1、直接去算次数(统计哪个数在第几位,然后去运算)
2、模拟操作
贴一个别人的代码。。。https://blog.csdn.net/weixin_39453270/article/details/80548780
#include <bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
string str1,str2;
bool vis=;
void Get(char a,char b,int n,int &ans){
str2=str1;
int cnt=;
int tmp=;
for(int i=n-;i>=;i--){//将最后一位置为字符b
if(str2[i]==b){
cnt++;
for(int j=i;j<n-;j++){
swap(str2[j],str2[j+]);
tmp++;
}
break;
}
}
for(int i=n-;i>=;i--){//将倒数第二位置为字符a
if(str2[i]==a){
cnt++;
for(int j=i;j<n-;j++){
swap(str2[j],str2[j+]);
tmp++;
}
break;
}
}
if(cnt==){//如果能够构成后缀ab
if(str2[]!=''){
vis=;
//cout<<tmp<<endl;
ans=min(ans,tmp);
}//如果有前导0
else{
for(int i=;i<n-;i++){
if(str2[i]!=''){//从第1位到n-2位找到第一个不为0的数
tmp+=i;
vis=;
ans=min(ans,tmp);
break;
}
}
}
}
}
int main()
{
cin>>str1;
int len=str1.length();
int ans=INF;
//四种情况贪心取最小
Get('','',len,ans);
Get('','',len,ans);
Get('','',len,ans);
Get('','',len,ans);
if(vis) cout<<ans<<endl;
else puts("-1");
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 (技巧的暴力)
You are given an integer nn from 11 to 10181018 without leading zeroes. In one move you can swap any ...
- 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 ...
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- CodeForces - 404B(模拟题)
Marathon Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Sta ...
- cdoj 25 点球大战(penalty) 模拟题
点球大战(penalty) Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...
随机推荐
- hdu2795 Billboard(线段树单点修改)
传送门 结点中的l和r表示层数,maxx表示这层最多还剩下多少宽度.根据公告的宽度取找到可以放的那一层 找到后返回层数,并修改maxx #include<bits/stdc++.h> us ...
- MYSQL 数据库结构优化
数据库结构优化 优化数据大小 使表占用尽量少的磁盘空间.减少磁盘I/O次数及读取数据量是提升性能的基础原则.表越小,数据读写处理时则需要更少的内存,同时,小表的索引占用也相对小,索引处理也更加快速. ...
- Dubbo问题处理集合
1 . 启动微服务的时候,报错信息如下: 核心:Can not lock the registry cache file /root/.dubbo/dubbo-registry-127.0.0.1.c ...
- 你也可以手绘二维码(二)纠错码字算法:数论基础及伽罗瓦域GF(2^8)
摘要:本文讲解二维码纠错码字生成使用到的数学数论基础知识,伽罗瓦域(Galois Field)GF(2^8),这是手绘二维码填格子理论基础,不想深究可以直接跳过.同时数论基础也是 Hash 算法,RS ...
- iOS 模块化、组件化方案探索(利用cocoapods 、git 创建私有仓库)
来自bang's blog http://blog.cnbang.net/tech/3080/ 模块化 简单来说,模块化就是将一个程序按照其功能做拆分,分成相互独立的模块,以便于每个模块只包含与其功能 ...
- Scrum Meeting 6 -2014.11.12
今天apec最后一天,大部分任务都差不多了,局部测试问题不大.大家修复下小细节就可以开始整合了. Member Today’s task Next task 林豪森 协助测试及服务器部署 协助测试及服 ...
- [buaa-SE-2017]个人作业-Week1
个人作业-Week1 Part1:教材中不懂的问题 1.根据书中"除了前20的学校之外,计科和软工没有区别"所以计算机科学这个专业也许在我们学校是和软件工程有区别的,但是可以料想的 ...
- ME.kkkK
ME.kkkK 一.预估与实际 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 50 40 • Estima ...
- 20162314 《Program Design & Data Structures》Learning Summary Of The First Week
20162314 2017-2018-1 <Program Design & Data Structures>Learning Summary Of The First Week ...
- 优化Hibernate所鼓励的7大措施:
优化Hibernate所鼓励的7大措施: 1.尽量使用many-to-one,避免使用单项one-to-many 2.灵活使用单向one-to-many 3.不用一对一,使用多对一代替一对一 4.配置 ...