cdoj第13th校赛初赛F - Fabricate equation
http://acm.uestc.edu.cn/#/contest/show/54
F - Fabricate equation
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
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的更多相关文章
- cdoj第13th校赛初赛H - Hug the princess
http://acm.uestc.edu.cn/#/contest/show/54 H - Hug the princess Time Limit: 3000/1000MS (Java/Others) ...
- cdoj第13th校赛初赛L - Lovely princess
http://acm.uestc.edu.cn/#/contest/show/54 L - Lovely princess Time Limit: 3000/1000MS (Java/Others) ...
- 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 ...
- 2017校赛 问题 F: 懒人得多动脑
题目描述 小D的家A和学校B都恰好在以点F为焦点的双曲线上,而小D每日所需的生活水源在一条平行该双曲线准线的直线上,设它的值为v.大家都知道,每天都是要喝水的,但是小D有点懒,他希望自己能在去上学或者 ...
- 校赛F
问题描述 例如对于数列[1 2 3 4 5 6],排序后变为[6 1 5 2 4 3].换句话说,对于一个有序递增的序列a1, a2, a3, ……, an,排序后为an, a1, an-1, a2, ...
- 校赛F 比比谁更快(线段树)
http://acm.cug.edu.cn/JudgeOnline/problem.php?cid=1153&pid=5 题意:给你一个字符串,各两个操作: ch=0,[l,r]降序 ch=1 ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- 2014上半年acm总结(1)(入门+校赛)
大一下学期才开始了acm,不得不说有一点迟,但是acm确实使我的生活充实了很多,,不至于像以前一样经常没事干= = 上学期的颓废使我的c语言学的渣的一笔..靠考前突击才基本掌握了语法 寒假突然醒悟, ...
- HZNU第十二届校赛赛后补题
愉快的校赛翻皮水! 题解 A 温暖的签到,注意用gets #include <map> #include <set> #include <ctime> #inclu ...
随机推荐
- maven学习(6)-Maven依赖范围
一.maven依赖范围: classpath 分为三种:编译classpath , 测试classpath , 运行classpath Scope 选项如下: Compile:编译依赖范围.默认就是c ...
- POJ 2139 Six Degrees of Cowvin Bacon (floyd)
Six Degrees of Cowvin Bacon Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Ja ...
- shell 10流程控制
if 判断 if #shell #!/bin/sh a=5 if [[ $a > 3 ]];then echo "$a>3" fi #写成一行 if [[ $a < ...
- 第9课 const和volatile分析
1. const只读变量——(注意不是真正常量,只是告诉编译器不能出现在赋值号左边!) (1)const修饰的变量是只读的,本质还是变量 (2)const修饰的局部变量在栈上分配空间 (3)const ...
- ubuntu18.04修改时区
运行如下命令: sudo tzselect 然后选择亚洲Asia,继续选择中国China,最后选择北京Beijing. 然后创建时区软链 sudo ln -sf /usr/share/zoneinfo ...
- 小朋友学Java(1):Mac系统安装JDK
1 打开终端 方法可以参考http://blog.csdn.net/haishu_zheng/article/details/73410594 2 在终端输入 java -version,提示没有Ja ...
- 20180129周一之学习PYTHON笔记【PYTHON2写个自动点击学习功能】
pyautogui.click(pyautogui.center(pyautogui.locateOnScreen('sy.png'))) #点击该截图一次 --------------------- ...
- robot framework取出列表子元素
取出嵌套列表变量的子元素 ${list}型列表: ${list} = [["A1", "first"], ["A2", "seco ...
- eclipse 断点找到同名的其它类
转载自Eclipse断点进入另一个项目的同名Java文件中(http://tunps.com/p/11789.html) eclipse 断点找到同名的其它类 A和B是两个相同的项目,A一直本地,B是 ...
- ABAP-关于隐式与显式的DB Commit
转载:https://www.cnblogs.com/liaojunbo/archive/2011/07/11/2103491.html 1.显式的DB Commit 显式的DB Commit并没有对 ...