我对贪心的理解: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. Just a Hook(线段树)

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. Dajngo admin使用

    Dajngo admin使用 Django 提供了基于 web 的管理工具. Django 自动管理工具是 django.contrib 的一部分.你可以在项目的 settings.py 中的 INS ...

  3. Android 主线程和子线程通信问题

        Android 如今不支持View在子线程中创建及调用其方法.假设要实现子线程内容更新之后.将结果及时反馈到主线程中,该怎样出来呢?     能够在主线程中创建Handler来实现. 这样子线 ...

  4. Arduino 看门狗使用

    1.需要调用 #include <avr/wdt.h> 2.设置看门狗复位时间 wdt_enable(WDTO_2S); 代码时间定义的底层查看 #define WDTO_15MS 0 / ...

  5. oldboyshell编程扩展内容

    oldboyshell编程扩展内容一.命令的优先级 命令分为: ==> alias ==> Compound Commands ==> function  ==> build_ ...

  6. Jmeter使用文档(windows)

    1. 安装jdk并配置环境变量 以1.8为例: (1)安装jdk1.8; (2)在系统变量里点击新建,变量名填写JAVA_HOME,变量值填写JDK的安装路径“C:\Program Files\Jav ...

  7. MySQL的进程状态

    通过show processlist查看MySQL的进程状态,在State列上面的状态有如下这些: Analyzing线程对MyISAM 表的统计信息做分析(例如, ANALYZE TABLE ).c ...

  8. castle windsor学习-----Inline dependencies 依赖

    应用程序中的很多组件都会依赖其他的服务组件,很多依赖一些不合法的组件或者容器中没有的组件,例如int类型.string类型.TimeSpan类型 Windsor支持以上的场景,注册API有Depend ...

  9. 《thinking in java》 接口与内部类

    书本上的例子 改编后的. package test2; class A{ interface B{void f();} public class BImp implements B{public vo ...

  10. 利用create-react-app从零开始搭建React移动端环境

    一 开始 1 全局安装脚手架 npm install -g create-react-app 这有个坑,就是在window下安装一直会报错,报错信息如下: 解决办法:在开始菜单栏里打开cmd的时,右击 ...