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