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

  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. Linu之linux系统基础优化和基本命令

    Linux系统基础优化和基本命令 网络参数设定命令 ifconfig: 查询,设置网卡和ip等参数 ifup,ifdown: 脚本命令,更简单的方式 ip: 符合指令,直接修改上述功能 编辑网卡配置文 ...

  2. python解释 yield 和 Generators(生成器)

    yield 和 Generators(生成器) 转自:http://www.oschina.net/translate/improve-your-python-yield-and-generators ...

  3. Caffe Blob针对图像数据在内存中的组织方式

    Caffe使用Blob结构在CNN网络中存储.传递数据.对于批量2D图像数据,Blob的维度为 图像数量N × 通道数C × 图像高度H × 图像宽度W 显然,在此种场景下,Blob使用4维坐标定位数 ...

  4. Java字符串连接操作的性能问题

    首先,看一段实验程序: package com.test; class StringTest { public static void main(String[] args) { long start ...

  5. beego跨域请求配置

    不说废话 在main函数前加入如下代码 func init() { //跨域设置 var FilterGateWay = func(ctx *context.Context) {ctx.Respons ...

  6. CHAPTER 40 Science in Our Digital Age 第40章 我们数字时代的科学

    CHAPTER 40 Science in Our Digital Age 第40章 我们数字时代的科学 The next time you switch on your computer, you ...

  7. Centos 7 安装Zabbix

    一.环境准备与说明: 1.zabbix server 版本:3.4.12 ,https://www.zabbix.com/download 2.zabbix agent版本:3.4.14,https: ...

  8. Django_rest_framework_渲染器/解析器/路由控制/分页

    目录 渲染器 解析器 路由控制 分页 渲染器 简介 什么是渲染器 根据 用户请求URL 或 用户可接受的类型,筛选出合适的 渲染组件. 渲染器的作用 序列化.友好的展示数据 渲染器配置 首先要在set ...

  9. 局域网传输-LED灯搭建局域网:数据传输可达每秒3Gb

    一 : LED灯搭建局域网:数据传输可达每秒3Gb 我们之前介绍了利用可见光通讯技术,通过LED灯光实现精准室内定位的例子.实际上,这种灯泡和技术的用途不止于此,比如,它还能进行无线网络传输. 最近, ...

  10. 解决SecureCRT小键盘乱码

    SecureCRT软件菜单,Options -> Session Options ->Terminal -> Emulation,右侧面板中"Terminal"选 ...