遇见模拟题 有两种做法 例如这题:

  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(模拟)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces Round #486 (Div. 3) E. Divisibility by 25

    Codeforces Round #486 (Div. 3) E. Divisibility by 25 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  4. CF 988E Divisibility by 25 思维 第十二

    Divisibility by 25 time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. Codeforces 988E. Divisibility by 25

    解题思路: 只有尾数为25,50,75,00的数才可能是25的倍数. 对字符串做4次处理,以25为例. a. 将字符串中的最后一个5移到最后一位.计算交换次数.(如果没有找到5,则不可能凑出25,考虑 ...

  6. Codeforces Round #486 (Div. 3)988E. Divisibility by 25技巧暴力||更暴力的分类

    传送门 题意:给定一个数,可以对其做交换相邻两个数字的操作.问最少要操作几步,使得可以被25整除. 思路:问题可以转化为,要做几次交换,使得末尾两个数为00或25,50,75: 自己一开始就是先for ...

  7. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  8. CodeForces - 404B(模拟题)

    Marathon Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Sta ...

  9. cdoj 25 点球大战(penalty) 模拟题

    点球大战(penalty) Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...

随机推荐

  1. Git 个人笔记

     最近在看 Git ,顺便把这些常用命令记录下来,以备以后忘记能查看(未完):   // 设置用户名和邮箱  使用global 表示这台主机上所有的Git仓库都会使用这个配置  也可以对某个仓库指定不 ...

  2. [PLC]ST语言三:OUT/OUT_T/OUT_C/OUT_C-C32

    一:OUT/OUT_T/OUT_C/OUT_C-C32               说明:简单的顺控指令不做其他说明. 控制要求:无 编程梯形图: 结构化编程ST语言: (*OUT(EN,D);*) ...

  3. python图像处理(2)图像水印和PIL模式转化

    模式转化: PIL模式转化:将图片转化成其他模式 # 我们将image图像转化为灰度图像(python) from PIL import Image img = Image.open('c:\\1.J ...

  4. Unity学习笔记(4): 碰撞相关API

    Unity3D中的碰撞: 在unity中,有普通碰撞体Collider和触发器(Trigger)两种碰撞体,两个普通碰撞体会发生碰撞并产生力学现象,触发器则像是个无法触碰而又真实存在的东西,也会触发碰 ...

  5. Linux AD 身份统一验证(SSO)

    http://www.toxingwang.com/linux-unix/linux-admin/584.html Linux+samba-winbind+AD实现统一认证 2013年04月27日 ⁄ ...

  6. Netty源码分析第4章(pipeline)---->第3节: handler的删除

    Netty源码分析第四章: pipeline 第三节: handler的删除 上一小节我们学习了添加handler的逻辑操作, 这一小节我们学习删除handler的相关逻辑 如果用户在业务逻辑中进行c ...

  7. HTML(2)普通文本的修饰

    段落标签 <p> 我们使用<p>...</p>标签来标记一个段落,两个段落之间会自动换行.需要注意的是,在书写HTML时,连续的空格只被看作一个空格,如果需要插入空 ...

  8. It isn't possible to write into a document from an asynchronously-loaded

    It isn't possible to write into a document from an asynchronously-loaded   今天遇到了一个问题: 通过document.wri ...

  9. centos7安装oracle亲测可用

    http://www.linuxidc.com/Linux/2016-04/130559p2.htm

  10. 第九次作业psp

    psp 进度条 代码累积折线图 博文累积折线图 psp饼状图