传送门

题意:给定一个数,可以对其做交换相邻两个数字的操作。问最少要操作几步,使得可以被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. Angular JS 中的服务注册方法

    在Angular JS中创建服务的几种方法 factory() service() constant() value() provider() factory(name,fn(){}) 该服务为单例的 ...

  2. dz6.0的一个sql注入漏洞

    今天开始着手分析第一个漏洞,找了一上午靶机,发现一个含有成人内容的违法网站是用dz6.0搭的,今天就看看dz这个版本的洞了 问题函数位置:my.php第623行 if(is_array($descri ...

  3. Java连载10-数据类型取值范围&转义字符

    一.数据类型取值范围 二.八种数据类型在成员变量中的默认值 (1)成员变量,没有赋值,编译不会报错,系统会自动给赋值 byte\int\short\long默认值为0:float\double默认值为 ...

  4. Java集合系列(三):HashSet、LinkedHashSet、TreeSet的使用方法及区别

    本篇博客主要讲解Set接口的三个实现类HashSet.LinkedHashSet.TreeSet的使用方法以及三者之间的区别. 注意:本文中代码使用的JDK版本为1.8.0_191 1. HashSe ...

  5. MySQL中一些关于索引的知识点

    什么是索引 索引是一种数据结构,其作用就是用来提高数据查询效率.比较常用的比喻就是将其类比为书籍的目录.通过目录可以精确的找到某一章节的内容所在页. 在数据量较小的时候使用索引其实也没有什么意义,即使 ...

  6. NYOJ 53 最少步数

    题      目    http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=58 思路借鉴   DFS-Deep First Search-深度优先 ...

  7. Flink 从0到1学习—— 分享四本 Flink 国外的书和二十多篇 Paper 论文

    前言 之前也分享了不少自己的文章,但是对于 Flink 来说,还是有不少新入门的朋友,这里给大家分享点 Flink 相关的资料(国外数据 pdf 和流处理相关的 Paper),期望可以帮你更好的理解 ...

  8. 【JDK】JDK源码分析-AbstractQueuedSynchronizer(2)

    概述 前文「JDK源码分析-AbstractQueuedSynchronizer(1)」初步分析了 AQS,其中提到了 Node 节点的「独占模式」和「共享模式」,其实 AQS 也主要是围绕对这两种模 ...

  9. Docker 的另外两个话题: DockerHub 和 容器网络

    关注公众号,大家可以在公众号后台回复“博客园”,免费获得作者 Java 知识体系/面试必看资料. Hello,大家好,我是子悠,作为本周的小编昨天已经跟大家介绍过自己了,今天就让我们继续学习江南一点雨 ...

  10. 使用python画3D线条

    """用于验证整体趋势正确性""" #!python3 #-*- coding:utf-8 -*- import matplotlib as ...