当前位置:网站首页>【Codeforces】 B. Make it Divisible by 25
【Codeforces】 B. Make it Divisible by 25
2022-07-27 17:57:00 【tsunaa】
B. Make it Divisible by 25
The question :
Here's a bunch of numbers , Can remove some numbers from it . Ask at least how many numbers to remove , So that the number represented by this series of numbers can be 25 to be divisible by .
Ideas
Can be 25 Divisible number , It should be based on 00、25、50、75 Ending number . The form appearing in the number string should be as follows : It should be recorded :( From right to left )
… 0 … 0 … : the second 0, first 0
… 5 … 0 … : first 0, 0 The first after 5
… 2 … 5 … : first 5, 5 The first after 2
… 7 … 5 … : first 5, 5 The first after 7
AC Code :
#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;
}
}
边栏推荐
- From digitalization to intelligent operation and maintenance: what are the values and challenges?
- Taishan Office Technology Lecture: word strange paragraph borders
- Lichuang EDA - PCB layout (IV)
- Oracle 11g数据库安装教程
- Redis: configuring AOF does not work
- How to resolve the public domain name to the intranet IP server -- quickly resolve the domain name and map the Internet access
- Gree "not cool": the giant lawsuit ended and was reduced by large dealers. Is it too late for the new battlefield of air conditioning?
- Uncle's nephew and his students
- MySQL view and stored procedure
- How to restrict root remote login so that ordinary users have root privileges
猜你喜欢

笔试缺考者入围教师招聘面试?河南祥符:个别考生成绩统计错误

WebDriverException( selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executabl

Initial polymorphism

知物由学 | 再造巴别塔,我们如何进行NLP跨语言知识迁移?

可口可乐的首要挑战,不是元气森林

js实现右键菜单栏功能

Explain the pile of binary trees in detail

Kubernetes 1.24 high availability cluster binary deployment

Wechat applet to make calls

How to resolve the public domain name to the intranet IP server -- quickly resolve the domain name and map the Internet access
随机推荐
X-sheet development tutorial: initialization configuration custom layout
Mysql database defines cursor in trigger
The 7-year-old boy broke his finger by AI robot just because he played chess too fast?
Run loam_ Velodyne real-time mapping
vim的配置及基础使用
Redis: configuring AOF does not work
Introduction to Alibaba eagle eye system
卷积神经网络——YOLOV2(YOLO9000)论文翻译
奇瑞欧萌达也太像长安UNI-T了,但长得像,产品力就像吗?
[introduction to database system (Wang Shan)] Chapter 1 - Introduction
DDD(领域驱动设计)分层架构
微信小程序 实现拨打电话
Flutter的布局
[OBS] newsocketloopenable network optimization
Microsoft silently donated $10000 to curl, which was not notified until half a year later
详解分布式系统的幂等
kubernetes 1.24高可用集群二进制部署
Talk about the new trend of machine translation, and the second maverick translation forum is about to open
Zhengzhou University database course resource description
【数据库系统概论(王珊)】第11章 并发控制