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. setting.xml配置文件 --转载

    转载出处:http://www.cnblogs.com/yakov/archive/2011/11/26/maven2_settings.html 在此,简单的说下 setting.xml 和 pom ...

  2. Codeforces Round #506 D. Concatenated Multiples题解

    一.传送门 http://codeforces.com/contest/1029/problem/D 二.题意 给你$N$个数字$a_1,a_2,\cdots,a_n$,一个$K$,求所有$i \ne ...

  3. 第8章 信号(6)_贯穿案例2:mini shell(3)

    4. 贯穿案例2:mini shell(3) (1)之前存在问题 ①刚运行时,mshell作为前台进程.运行的其他命令会被加入新的进程组,并且调用tcsetpgrp将这个进程组设置为前台进程组,因此m ...

  4. Linux系统运行级与启动机制剖析

    原文作者:技术成就梦想 原文链接:http://ixdba.blog.51cto.com/2895551/533740 一 系统运行级windows系统有安全运行模式和正常运行模式,这是两个不同的运行 ...

  5. 给iOS开发新手送点福利,简述UIPikerView的属性和用法

    1.   numberOfComponents:返回UIPickerView当前的列数 NSInteger num = _pickerView.numberOfComponents; NSLog( @ ...

  6. Python3 os模块应用

    调用模块的实质是运行python代码,比如a.py文件里有函数f(),那么你在调用a模块的时候,实质是运行了a模块里的函数f(),这个时候内存里就有这个函数了,可以直接用,那是不是随便一个py类型的文 ...

  7. 小朋友学C++(2)

    多态 (一) 先编写函数: #include <iostream> using namespace std; class Shape { protected: int width, hei ...

  8. mongodb中查询返回指定字段

    mongodb中查询返回指定字段   在写vue项目调用接口获取数据的时候,比如新闻列表页我只需要显示新闻标题和发表时间,点击每条新闻进入详情页的时候才会需要摘要.新闻内容等关于此条新闻的所有字段.  ...

  9. NHibernate.Cfg.HibernateConfigException

    在用NHibernate 框架做web 项目时,当项目被成功编译后,按F5 启动调试时,一开始就出现这个错误,刚开始就很郁闷,到底出在哪里?连自己都 不知道,在网上搜来搜去,找了很多的资料终于弄明白了 ...

  10. jmeter测试20个QPS下的响应时间-设置QPS限制

    添加--->定时器--->Constant Throughput Timer Constant Throughput Timer 的主要属性介绍: 名称:定时器的名称 Target thr ...