CF1060B:Maximum Sum of Digits
我对贪心的理解:https://www.cnblogs.com/AKMer/p/9776293.html
题目传送门:http://codeforces.com/problemset/problem/1060/B
显然贪一点能怼出\(9\)就往死里怼嘛……然后就直接算就行了。
时间复杂度:\(O(len)\)
空间复杂度:\(O(1)\)
代码如下:
#include <cstdio>
using namespace std;
#define ll long long
ll a,b;
ll read() {
	ll x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return x*f;
}
int S(ll num) {
	int res=0;
	while(num)res+=num%10,num/=10;
	return res;
}
int main() {
	a=read();
	while(b<=a)b=b*10+9;
	b/=10;printf("%d\n",S(b)+S(a-b));
	return 0;
}
CF1060B:Maximum Sum of Digits的更多相关文章
- CodeForces 1060 B Maximum Sum of Digits
		Maximum Sum of Digits You are given a positive integer n. Let S(x)S(x) be sum of digits in base 10 r ... 
- cf#513  B. Maximum Sum of Digits
		B. Maximum Sum of Digits time limit per test 2 seconds memory limit per test 512 megabytes input sta ... 
- Maximum Sum of Digits(CodeForces 1060B)
		Description You are given a positive integer nn. Let S(x) be sum of digits in base 10 representation ... 
- Codeforces_B.Maximum Sum of Digits
		http://codeforces.com/contest/1060/problem/B 题意:将n拆为a和b,让a+b=n且S(a)+S(b)最大,求最大的S(a)+S(b). 思路:考虑任意一个数 ... 
- CodeForces 489C Given Length and Sum of Digits... (贪心)
		Given Length and Sum of Digits... 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/F Descr ... 
- codeforces#277.5 C. Given Length and Sum of Digits
		C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ... 
- CodeForces 489C Given Length and Sum of Digits... (dfs)
		C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ... 
- B - Given Length and Sum of Digits... CodeForces - 489C (贪心)
		You have a positive integer m and a non-negative integer s. Your task is to find the smallest and th ... 
- POJ2479 Maximum sum[DP|最大子段和]
		Maximum sum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39599 Accepted: 12370 Des ... 
随机推荐
- jsp中嵌入的java代码执行对html的影响方式
			1 直接输出html标签嵌入到html中 <body> <h1>显示当前时间和日期</h1> <% Date date = new Date(); out.p ... 
- Python的自省机制
			什么是自省? 在日常生活中,自省(introspection)是一种自我检查行为. 在计算机编程中,自省是指这种能力:检查某些事物以确定它是什么.它知道什么以及它能做什么.自省向程序员提供了极大的灵活 ... 
- This instability is a fundamental problem for gradient-based learning in deep neural networks.  vanishing exploding gradient problem
			The unstable gradient problem: The fundamental problem here isn't so much the vanishing gradient pro ... 
- 深入 JavaScript 中的对象以及继承原理
			ES6引入了一个很甜的语法糖就是 class, class 可以帮助开发者回归到 Java 时代的面向对象编程而不是 ES5 中被诟病的面向原型编程. 我也在工作的业务代码中大量的使用 class, ... 
- Dubbo,ZooKeeper,Redis,FastDFS,ActiveMQ,Keepalived,Nginx,Hudson
			获取[下载地址] QQ: 313596790 [免费支持更新] 三大数据库 mysql oracle sqlsever 更专业.更强悍.适合不同用户群体 [新录针对本系统的视频教程,手 ... 
- CentOS7.x 报错 There are no enabled repos.
			地址 :http://mirrors.163.com/centos/7/os/x86_64/Packages/ wget http://mirrors.163.com/centos/7/os/x8 ... 
- Ubuntu 13.04 可以使用的源
			以下为收集的Ubuntu 13.04 可以使用的源 #中科大源deb http://mirrors.ustc.edu.cn/ubuntu/ saucy main restricted universe ... 
- 【SHARE】WEB前端学习资料
			参考资料:https://github.com/karlhorky/learn-to-program 学习网站:http://www.codecademy.com/learn https://www. ... 
- sql查询报错:Every derived table must have its own alias
			执行sql语句出现语法错误 Every derived table must have its own alias 翻译:每个派生表都有自己的别名 
- js实现select动态添加option
			关于 select 的添加 option 应该注意的问题. 标准的做法如上也就是说,标准的做法是 s.options.add();但是如果你一定要用 s.appendChild(option);注意了 ... 
