http://acm.uestc.edu.cn/#/contest/show/54

F - Fabricate equation

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
Submit Status

Given an integer Y, you need to find the minimal integer K so that there exists a X satisfying X−Y=Z(Z≥0) and the number of different digit between X and Z is K under decimal system.

For example: Y=1, you can find a X=100 so that Z=99 and K is 3 due to 1≠0 and 0≠9. But for minimization, we should let X=1 so that Z=0 and K can just be 1.

Input

Only one integer Y(0≤Y≤1018).

Output

The minimal K.

Sample input and output

Sample Input Sample Output
1
1
191
2

思路:贪心。倒着扫描,遇到0就忽略,因为对应被减数的该位也设0就好;遇到9,这个特殊,因为比如290-191=99,后面进位后,9这个位也可以使得被减数与结果的该位相同,这样的情况需要两个条件:必须后面可以进位。假如减数那位为0,不论结果为什么,都无法产生进位。第二个条件是,被减数的前一位可以借位,也就是说9这种情况完成后,即便前面遇到减数那位为0,也不能再忽略,只能当一般情况处理。一般情况自然就是k++。

官方题解:

代码:

 #include <fstream>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <vector> using namespace std; #define PI acos(-1.0)
#define EPS 1e-10
#define lll __int64
#define ll long long
#define INF 0x7fffffff char c[]; int main(){
//freopen("D:\\input.in","r",stdin);
//freopen("D:\\output.out","w",stdout);
scanf("%s",c+);
int l=strlen(c+),k=;
c[l+]='';c[]='';
for(int i=l;i>;i--){
if(c[i]=='') continue;
if(c[i]==''){
if(c[i+]==''){
k++;
continue;
}else{
if(c[i-]=='') c[i-]++;//把前面的0毁掉
continue;
}
}else{
k++;
}
}
if(c[]!='') k++;
printf("%d\n",k);
return ;
}

cdoj第13th校赛初赛F - Fabricate equation的更多相关文章

  1. cdoj第13th校赛初赛H - Hug the princess

    http://acm.uestc.edu.cn/#/contest/show/54 H - Hug the princess Time Limit: 3000/1000MS (Java/Others) ...

  2. cdoj第13th校赛初赛L - Lovely princess

    http://acm.uestc.edu.cn/#/contest/show/54 L - Lovely princess Time Limit: 3000/1000MS (Java/Others) ...

  3. cdoj第13th校赛初赛A - AC Milan VS Juventus 【枚举】

    http://acm.uestc.edu.cn/#/contest/show/54 A - AC Milan VS Juventus Time Limit: 3000/1000MS (Java/Oth ...

  4. 2017校赛 问题 F: 懒人得多动脑

    题目描述 小D的家A和学校B都恰好在以点F为焦点的双曲线上,而小D每日所需的生活水源在一条平行该双曲线准线的直线上,设它的值为v.大家都知道,每天都是要喝水的,但是小D有点懒,他希望自己能在去上学或者 ...

  5. 校赛F

    问题描述 例如对于数列[1 2 3 4 5 6],排序后变为[6 1 5 2 4 3].换句话说,对于一个有序递增的序列a1, a2, a3, ……, an,排序后为an, a1, an-1, a2, ...

  6. 校赛F 比比谁更快(线段树)

    http://acm.cug.edu.cn/JudgeOnline/problem.php?cid=1153&pid=5 题意:给你一个字符串,各两个操作: ch=0,[l,r]降序 ch=1 ...

  7. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  8. 2014上半年acm总结(1)(入门+校赛)

    大一下学期才开始了acm,不得不说有一点迟,但是acm确实使我的生活充实了很多,,不至于像以前一样经常没事干=  = 上学期的颓废使我的c语言学的渣的一笔..靠考前突击才基本掌握了语法 寒假突然醒悟, ...

  9. HZNU第十二届校赛赛后补题

    愉快的校赛翻皮水! 题解 A 温暖的签到,注意用gets #include <map> #include <set> #include <ctime> #inclu ...

随机推荐

  1. freemarker ,DEFAULT_INCOMPATIBLE_IMPROVEMENTS 找不到

    一般出现这种问题的原因是,spring的版本和freemarker不匹配造成的~ nested exception is org.springframework.beans.factory.BeanC ...

  2. ue4 多相机分屏与小地图效果实现教程

    转自:http://blog.csdn.net/shenmifangke/article/details/51940007  通过使用ue4的UI和rendertarget来实现 优点就是可以随意设置 ...

  3. Mysql导出表结构、表数据

    导出 (cmd)     1.导出數據库為dbname的表结构(其中用戶名為root,密码為dbpasswd,生成的脚本名為db.sql)    mysqldump -u root -p dbpass ...

  4. Python预编译语句防止SQL注入

    这个月太忙,最近不太太平,我的愿望是世界和平! ================================== 今天也在找python的预编译,早上写的sql是拼接来构成的.于是找了2篇文章,还 ...

  5. PyQt5系列教程(七)控件

    软硬件环境 Windows 10 Python 3.4.2 PyQt 5.5.1 PyCharm 5.0.4 前言 控件是PyQt应用程序的基石.PyQt5自带很多不同的控件,包括像button.ch ...

  6. python读取excel,数字都是浮点型,日期格式是数字的解决办法

    excel文件内容: 读取excel: # coding=utf-8 import xlrd import sys reload(sys) sys.setdefaultencoding('utf-8' ...

  7. jpa-入门.缓存配置ehcache.xml

    <ehcache> <!-- Sets the path to the directory where cache .data files are created. If the p ...

  8. SQL Server 2005 无法连接到WMI提供程序 无法执行 SQL Server 系统配置检查器

    无法连接到WMI提供程序.你没有权限或者该服务器无法访问/cannot connect to WMI provider. You do not have permission or the--由于计算 ...

  9. Spring Boot实践——用外部配置填充Bean属性的几种方法

    引用:https://blog.csdn.net/qq_17586821/article/details/79802320 spring boot允许我们把配置信息外部化.由此,我们就可以在不同的环境 ...

  10. java自定义线程池

    如果并发的线程数量很多,并且每个线程都是执行一个时间很短的任务就结束了,这样频繁创建线程就会大大降低系统的效率,因为频繁创建线程和销毁线程需要时间.那么有没有一种办法使得线程可以复用,就是执行完一个任 ...