Codeforces Round #486 (Div. 3)988E. Divisibility by 25技巧暴力||更暴力的分类
题意:给定一个数,可以对其做交换相邻两个数字的操作。问最少要操作几步,使得可以被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技巧暴力||更暴力的分类的更多相关文章
- Codeforces Round #486 (Div. 3) E. Divisibility by 25
Codeforces Round #486 (Div. 3) E. Divisibility by 25 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- Codeforces Round #486 (Div. 3) F. Rain and Umbrellas
Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- 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 ...
- Codeforces Round #486 (Div. 3) A. Diverse Team
Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...
- 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight
题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...
- 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/ ...
- 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 ...
- Codeforces Round #486 (Div. 3)988D. Points and Powers of Two
传送门:http://codeforces.com/contest/988/problem/D 题意: 在一堆数字中,找出尽量多的数字,使得这些数字的差都是2的指数次. 思路: 可以知道最多有三个,差 ...
- 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 ...
随机推荐
- [NSNull intValue]: unrecognized selector sent to instance 0x375c9860
今天遇到这个问题,程序崩溃了……日志如下: -[NSNull intValue]: unrecognized selector sent to instance 0x375c9860*** Termi ...
- 机房ping监控 smokeping+prometheus+grafana(续) 自动获取各省省会可用IP
一.前言 1.之前的文章中介绍了如何使用smokeping监控全国各省的网络情况:https://www.cnblogs.com/MrVolleyball/p/10062231.html 2.由于之前 ...
- 用python绘制漂亮的图形
先看效果,没有用任何绘图工具,只是运行了一段python代码. 代码如下: _ = ( 255, lambda V ,B,c :c and Y(V*V+B,B, c -1)if(abs(V)<6 ...
- 请使用switch语句和if...else语句,计算2008年8月8日这一天,是该年中的第几天。
请使用switch语句和if...else语句,计算2008年8月8日这一天,是该年中的第几天. #include <stdio.h> int main() { /* 定义需要计算的日期 ...
- Fragment 使用详解
极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以 ...
- Java实现调用Bartender控制条码打印机
官方提供的主要是C#支持. 基于java调用bartender二次开发官方给了一份1998年的J#代码,,,完全用不了,,,百度谷歌搜索万能的网友的答案,发现也没有可参考的.. 最后想到了之前用到了一 ...
- TensorFlow Data模块
模块作用 tf.data api用于创建训练前导入数据和数据处理的pipeline,使得处理大规模数据,不同数据格式和复杂数据处理变的容易. 基本抽象 提供了两种基本抽象:Dataset和Iterat ...
- SonarQube系列三、Jenkins集成SonarQube(dotnetcore篇)
[前言] 本系列主要讲述sonarqube的安装部署以及如何集成jenkins自动化分析.netcore项目.目录如下: SonarQube系列一.Linux安装与部署 SonarQube系列二.分析 ...
- mysql 输入show databases 没反应
我是小白,大佬勿喷 *** mysql 输入show databases 没反应 一句话 不要忘记使用MySQL时在命令后加;哦 * * * 在Linux输入以下命令 mysql 终端显示以下文本 W ...
- springboot整合solr
上一篇博客中简要写了solr在windows的安装与配置,这一篇接上文写一下springboot整合solr,代码已经上传到github,传送门. 1.新建core并配置schema 上篇博客中已经有 ...