我对贪心的理解: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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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). 思路:考虑任意一个数 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. POJ2479 Maximum sum[DP|最大子段和]

    Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 39599   Accepted: 12370 Des ...

随机推荐

  1. 九度OJ 1343:城际公路网 (最小生成树)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:445 解决:178 题目描述: 为了加快城市之间的通行和物资流动速度,A国政府决定在其境内的N个大中型城市之间,增加修建K条公路.已知这N个 ...

  2. api 爬虫 避免相同 input 在信息未更新 情况下 重复请求重复

  3. springboot带分页的条件查询

    QueryDSL简介 QueryDSL仅仅是一个通用的查询框架,专注于通过Java API构建类型安全的SQL查询. Querydsl可以通过一组通用的查询API为用户构建出适合不同类型ORM框架或者 ...

  4. The path "fos_user.from_email.address" cannot contain an empty value, but got null.

    The path "fos_user.from_email.address" cannot contain an empty value, but got null.. 修改 pa ...

  5. PHP实现今天是星期几的几种写法

    今天是星期几的写法有很多,本文整理了常用的三种. 代码如下:  // 第一种写法 $da = date("w");  if( $da == "1" ){  ec ...

  6. Git——基本操作(三)

    一.安装和配置 1.Git安装 yum install git -y 安装完Git就可以对其做一些配置: Git有一个工具被称为git config,它允许你获得和设置配置变量: 这些变量可以控制Gi ...

  7. MySQL常用代码

    create database 数据库名 create table CeShi1( Uid varchar(50) primary key, Pwd varchar(50), Name varchar ...

  8. 每天一个Linux命令(17)whereis命令

    whereis命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b).man说明文件(参数-m)和源代码文件(参数-s).如果省略参数,则返回所有信息.     (1)用法:   用法:    w ...

  9. [MEF] 学习之一 入门级的简单Demo

    MEF 的精髓在于插件式开发,方便扩展. 我学东西,习惯性的先搞的最简单的Demo出来,看看有没有好玩的东东,然后继续深入.这个博文,不谈大道理,看demo说事儿. 至于概念,请google ,大把大 ...

  10. 【leetcode刷题笔记】Unique Binary Search Trees II

    Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...