https://codeforces.com/contest/1060/problem/B

题意:给你一个数C ,你要找到两个数A、B,使得A+B=C并且A的每个位的数的和最大,求最大的和是多少

题解:肯定是9最大了,那么我们就要找最多有多少个9

   1.先找离这个数最大的10的幂次倍是多少,比如101最大的是100

   2.将离他最大的数减1即可得到最多的9的个数

   3.将这个数减去已经数过的9的那个数,得到另一个数,分解即可

代码如下:

#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define PI acos(-1)
#define eps 1e-8
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int maxn = 1e5+;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+;
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
double dpow(double a,LL b){double ans=1.0;while(b){if(b%)ans=ans*a;a=a*a;b/=;}return ans;} int main(){
#ifndef ONLINE_JUDGE
FIN
#endif
LL n;
cin>>n;
LL m=n;
LL cnt=;
LL tmp=;
while(m>){
tmp*=;
cnt++;
m/=;
}
tmp--;
LL t1=tmp;
LL t2=n-t1;
LL ans=;
while(t1){
ans+=t1%;
t1/=;
}
while(t2){
ans+=t2%;
t2/=;
}
cout<<ans<<endl; }

   

最新文章

  1. Leetcode: Palindrome Partitioning II
  2. JQuery学习思维导图版
  3. Android ViewFlipper控件实例
  4. 3、REST风格的URL
  5. 海量数据集利用Minhash寻找相似的集合【推荐优化】
  6. SDN第二次作业
  7. 上传视频使用ffmpeg自动截取缩略图
  8. 自适应rem.js
  9. BDD实战篇 - .NET Core里跑Specflow - 可以跑集成测试和单元测试
  10. (贪心) nyoj1036-非洲小孩
  11. [css] css3 中的新特性加强记忆
  12. JAVA基础-栈与堆,static、final修饰符、内部类和Java内存分配
  13. stm32 硬件错误
  14. 读取csv文件并打印其结果
  15. C# 获取listview中选中一行的值
  16. python关于时间的计算,time模块
  17. Transformer-view java实体 转换视图 Lists.transform
  18. C#-VS字符串、日期、时间和时间段
  19. MyEclipse中快速跳转到指定行号位置
  20. ConcurrentDictionary内部机制粗解

热门文章

  1. 003---socket介绍
  2. Python3 模块、包调用&amp;路径
  3. 【转】Ubuntu 14.04下Django+MySQL安装部署全过程
  4. C++11中initializer lists的使用
  5. 【廖雪峰老师python教程】——装饰器
  6. Django admin源码剖析
  7. session、token、cookie的区别
  8. jmeter+ant的使用
  9. Linux下的命令行
  10. SPOJ 375 Query on a tree(树链剖分)(QTREE)