当前位置:网站首页>【Codeforces】 B. Make it Divisible by 25
【Codeforces】 B. Make it Divisible by 25
2022-07-27 15:35:00 【tsunaa】
B. Make it Divisible by 25
题意:
给你一串数字,能从中移除一些数字。问最少移除多少个数字,使得这串数字代表的数能被25整除。
思路
能被25整除的数,应该是以00、25、50、75结尾的数。在数字串中出现的形式应该如下: 应该记录:(从右往左数)
… 0 … 0 … : 第二个0, 第一个0
… 5 … 0 … : 第一个0, 0之后的第一个5
… 2 … 5 … : 第一个5, 5之后的第一个2
… 7 … 5 … : 第一个5, 5之后的第一个7
AC代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int t;
ll n;
int a[20];
int digit(ll i){
int cnt = 0;
for(int i = 0; i <= 20; i++) a[i] = 0;
while(i){
a[++cnt] = i % 10;
i = i / 10;
}
reverse(a+1, a+1+cnt);
return cnt;
}
int main(){
cin >> t;
while(t--){
cin >> n;
int num = digit(n);
int first_0, second_0, first_5, second_5, second_7, second_2;
first_0 = second_0 = first_5 = second_5 = second_7 = second_2 = 0;
for(int i = num; i >= 1; i --) {
//00 50 75 25
//...0...0..
//...5...0..
//...7...5..
//...2...5
if(a[i] == 0 && (!first_0 || !second_0)){
if(!first_0) first_0 = i;
else second_0 = i;
}
else if(a[i] == 5){
if(!first_5) first_5 = i;
if(first_0 && !second_5) second_5 = i;
}
else if(a[i] == 7){
if(first_5 && !second_7) second_7 = i;
}
else if(a[i] == 2){
if(first_5 && !second_2) second_2 = i;
}
}
int ans1, ans2, ans3, ans4, ans;
ans1 = ans2 = ans3 = ans4 = 0x3f3f3f3f;
if(first_0 && second_0) ans1 = num - first_0 + first_0 - second_0 - 1;
if(first_0 && second_5) ans2 = num - first_0 + first_0 - second_5 - 1;
if(first_5 && second_7) ans3 = num - first_5 + first_5 - second_7 - 1;
if(first_5 && second_2) ans4 = num - first_5 + first_5 - second_2 - 1;
ans = min(ans1, min(ans2, min(ans3, ans4)));
cout << ans << endl;
}
}
边栏推荐
- With the arrival of large displacement hard core products, can the tank brand break through the ceiling of its own brand?
- Can deep learning overturn video codec? The first prize winner of the National Technological Invention Award nags you in the little red book
- SVM+Surf+K-means花朵分类(Matlab)
- 20年前,他是马云最大的敌人
- Uncle's nephew and his students
- 三表联查1
- 记一次 .NET 某智慧物流 WCS系统 CPU 爆高分析
- 腾讯云上传使用
- General process of background management system permission setting
- Purchase in Appstore
猜你喜欢

国产新冠口服药为什么是治艾滋病的药

大厂们终于无法忍受“加一秒”了,微软谷歌Meta等公司提议废除闰秒

Switch and router technology-02-working principle of Ethernet switch

Kubernetes第七篇:使用kubernetes部署prometheus+grafana监控系统(Kubernetes工作实践类)

详解分布式系统的幂等

一文理解分布式开发中的服务治理

The chess robot broke the finger of a 7-year-old boy. Netizen: it violated the first law of robots

Built in object (bottom)

The 7-year-old boy broke his finger by AI robot just because he played chess too fast?

Kubernetes第八篇:使用kubernetes部署NFS系统完成数据库持久化(Kubernetes工作实践类)
随机推荐
下棋机器人折断7岁男孩手指,网友:违反了机器人第一定律
With the arrival of large displacement hard core products, can the tank brand break through the ceiling of its own brand?
URL return nil and urlhash processing
Three table joint query 2
Database hyperphone (III)
立创EDA——原理图的布局与检查(三)
Lichuang EDA - PCB layout (IV)
High precision timer
Kubernetes Chapter 8: deploy NFS system with kubernetes to complete database persistence (kubernetes work practice class)
Gradient ring progress bar
国产新冠口服药为什么是治艾滋病的药
Oracle-Linux-7.9是否能支持Oracle-19c的ACFS文件系统?
Understand the staticarea initialization logic of SAP ui5 application through the initialization of fileuploader
[OBS] newsocketloopenable network optimization
数据库超话(三)
Motion capture system for end positioning control of flexible manipulator
Basic use and optimization of uitableview
High cost, difficult to implement, slow to take effect, what about open source security?
Shell programming specifications and variables
详解二叉树之堆