传送门

题意:给定一个数,可以对其做交换相邻两个数字的操作。问最少要操作几步,使得可以被25整除。

思路:问题可以转化为,要做几次交换,使得末尾两个数为00或25,50,75;

  自己一开始就是先for一遍,记录四种可能对于的步数,再对四种可能讨论(有前导0的情况);自己是在数据中,该对了自己的代码,

  看了队长和%王宣凯的代码,觉得那才是现场能ac的思路。--暴力交换;

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std; #define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue #define Pll pair<ll,ll>
#define Pii pair<int,int> #define fi first
#define se second #define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f; /*-----------------show time----------------*/
ll n;
string str;
int a[][];
int main(){ cin>>str;
int len = str.length();
reverse(str.begin(),str.end());
int flag0=,flag5=;
memset(a,inf,sizeof(a));
for(int i=;i<len; i++) //先记录所有可能的四种情况。
{
if(str[i]=='')
{
if(a[][]==inf)a[][] = i-;
}
else if(str[i]=='')
{
if(a[][]!=inf&&a[][]==inf)
{
a[][] = i + ;
}
else if(a[][]==inf)
{
a[][] = i;
}
if(a[][]==inf)
{
a[][] = i;
}
else if(a[][]==inf)a[][] = i-;
}
else if(str[i]=='')
{
if(a[][]!=inf&&a[][]==inf)
{
a[][] = i + ;
}
else if(a[][]==inf)
{
a[][] = i;
} if(a[][]==inf)a[][] = i-; if(a[][]!=inf&&a[][]==inf)
{
a[][] = i + ;
}
else if(a[][]==inf)
{
a[][] = i;
}
}
else if(str[i]=='')
{
if(a[][]==inf)a[][] = i-;
}
}
int ans = -;
for(int i=; i<=;i ++) //这里要确定会不会在交换中有0的情况。
{
if(a[i][]!=inf&&a[i][]!=inf&&(i==||i==))
{
char q,w;
int id = i;
if(id==) q = '',w = '';
// if(id==2) q = '5',w = '0';
if(id==) q = '',w = '';
// if(id==4) q = '0',w = '0';
int tot = ;
// debug(id);
int flag1 = ,flag2 = ;
for(int i=;i<len; i++)
{
if(q==str[i]&&i!=len-)flag1 = ;
if(w==str[i]&&i!=len-)flag2 = ;
}
if(flag1==||flag2==)
for(int i=len-; i>=; i--)
{
if(str[i] != q && str[i]!= w &&str[i]!='')break;
if(str[i]=='')tot++;
}
int tmp = a[i][] + a[i][] + tot;
if(ans==-)ans =tmp;
else ans = min(ans,tmp);
}
else if(a[i][]!=inf&&a[i][]!=inf)
{
char q,w;
q = '',w = '';
int tot = ;
// debug(id);
int flag1 = ,flag2 = ;
int tt = ; //记录0的个数
for(int i=;i<len; i++)
{
if(q==str[i]&&i!=len-)flag1 = ;
if(w==str[i]&&i!=len-)tt++;
}
if(i==||tt==)flag1=,flag2=;
if(flag1==||flag2==)
{
for(int i=len-; i>=; i--)
{
if(str[i] != q &&str[i]!='')break;
if(str[i]=='')tot++;
}
tot--;
}
int tmp = a[i][] + a[i][] + tot;
if(ans==-)ans =tmp;
else ans = min(ans,tmp);
}
}
cout<<ans<<endl;
return ;
}

自己写的分类讨论

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std; #define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue #define Pll pair<ll,ll>
#define Pii pair<int,int> #define fi first
#define se second #define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f; /*-----------------show time----------------*/ string str,tmp;
int cnt = ;
int sw(char a,int len)
{
for(int i=len;i>=;i--)
{
int t = ;
if(tmp[i]==a)
{
for(int j=i;j<len;j++)
swap(tmp[j],tmp[j+]),t++;
return t;
}
}
return inf;
}
int main(){
cin>>str;
int len = str.length();
int ans = inf;
//
int x;
tmp = str;
x = sw('',len-);
x += sw('',len-);
int i;
for(cnt = , i=; i<len&&tmp[i]=='' ;i++)cnt++;
ans = min(ans,x + cnt);
//一开始写成了for(int i=0,cnt = 0; i<len&&tmp[i]=='0' ;i++)cnt++;
//使得cnt的计数出了循环就没了效果。
//
tmp = str;
x = sw('',len-);
x += sw('',len-); for(cnt = , i=; i<len&&tmp[i]=='' ;i++)cnt++;
ans = min(ans,x + cnt);
//
tmp = str;
x = sw('',len-);
x += sw('',len-); for(cnt = , i=; i<len&&tmp[i]=='' ;i++)cnt++;
ans = min(ans,x + cnt); //
tmp = str;
x = sw('',len-);
x += sw('',len-); for(cnt = , i=; i<len&&tmp[i]=='' ;i++)cnt++;
ans = min(ans,x + cnt);
if(ans>=inf)puts("-1");
else
cout<<ans<<endl;
return ;
}

%mxk

Codeforces Round #486 (Div. 3)988E. Divisibility by 25技巧暴力||更暴力的分类的更多相关文章

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

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

  2. Codeforces Round #486 (Div. 3) F. Rain and Umbrellas

    Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  3. Codeforces Round #486 (Div. 3) D. Points and Powers of Two

    Codeforces Round #486 (Div. 3) D. Points and Powers of Two 题目连接: http://codeforces.com/group/T0ITBvo ...

  4. Codeforces Round #486 (Div. 3) A. Diverse Team

    Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...

  5. 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight

    题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...

  6. 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/ ...

  7. Codeforces Round #486 (Div. 3)-B. Substrings Sort

    B. Substrings Sort time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  8. Codeforces Round #486 (Div. 3)988D. Points and Powers of Two

    传送门:http://codeforces.com/contest/988/problem/D 题意: 在一堆数字中,找出尽量多的数字,使得这些数字的差都是2的指数次. 思路: 可以知道最多有三个,差 ...

  9. Codeforces Round #486 (Div. 3)-C. Equal Sums

    C. Equal Sums time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

随机推荐

  1. asp.net ashx处理程序中switch case的替代方案总结

    目录 1.用委托字典代替switch...case; 2.利用反射替代switch...case: 3.比较两种方案 4.其他方案 4.说明 5.参考 在开发 asp.net 项目中,通常使用一般处理 ...

  2. 灰度级分层(一些基本的灰度变换函数)基本原理及Python实现

    1. 基本原理 灰度级分层通常用于突出感兴趣的特定灰度范围内的亮度.灰度级分层有两大基本方法. 将感兴趣的灰度范围内的值显示为一个值(比如0),而其他范围的值为另外一个值(255). 将感兴趣的灰度范 ...

  3. Linux curl 常用示例

    本篇文章包含了curl的常用案例使用. 如果想了解curl选项的详细说明,请参考前一篇文章「Linux curl 命令详解」. 常见网页访问示例 基本用法 访问一个网页 curl https://ww ...

  4. MySQL储存过程详解

    我们常用的操作数据库语言SQL语句在执行的时候需要要先编译,然后执行,而存储过程(Stored Procedure)是一组为了完成特定功能的SQL语句集,经编译后存储在数据库中,用户通过指定存储过程的 ...

  5. Mysql 局域网连接设置——Windows

    在公司工作中,会遇到mysql数据库存储于某个人的电脑上,大家要想连接mysql服务,装有mysql服务的电脑就必须开启远程连接. 其实不仅仅是局域网,只要你有数据库所在服务器的公网IP地址都能连上. ...

  6. pythonday01计算机初步认识

    1.计算机的初步认识 常见的操作系统: win:xp,win7,win8,win10,windows server linux:centos图形化界面差,ubuntu个人开发,图形界面好,redhat ...

  7. 什么是Kafka?

    通过Kafka的快速入门 https://www.cnblogs.com/tree1123/p/11150927.html 能了解到Kafka的基本部署,使用,但他和其他的消息中间件有什么不同呢? K ...

  8. Git原理入门简析

    为了获得更好的阅读体验,建议访问原地址:传送门 前言: 之前听过公司大佬分享过 Git 原理之后就想来自己总结一下,最近一忙起来就拖得久了,本来想塞更多的干货,但是不喜欢拖太久,所以先出一版足够入门的 ...

  9. Python入门基础(10)_异常_1

    最近有点忙,到现在快一个月没写了,罪过罪过,继续学习 异常:python程序在运行时,如果python解释器遇到一个错误,那么程序就会停止执行,并且会提示一些错误信息,这就是异常. 抛出异常:程序停止 ...

  10. React预备知识点

    1.react中的状态提升 react的状态提升就是用户对子组件操作,子组件不改变自己的状态,而是通过自己的props把操作改变的数据传递给父组件,改变父组件的状态,从而改变受父组件控制的所有子组件的 ...