AtCoder题解 —— AtCoder Beginner Contest 187 —— A - Large Digits

保姆级教程:用Unity为麒麟系统打包Linux应用(含路径权限全攻略) 本文提供了一份详细的Unity跨平台开发指南,重点介绍如何在麒麟系统上打包和部署Linux应用。从开发环境配置、路径权限处理到性能优化和常见问题解决,全面解析了Unity项目在国产操作系统上的适配流程,帮助开发者高效完成跨平台应用开发。 阅读详情

题目相关

题目链接

AtCoder Beginner Contest 187 A 题,https://atcoder.jp/contests/abc187/tasks/abc187_a。

Problem Statement

For an integer n n n, let S ( n ) S(n) S(n) be the sum of digits in the decimal notation of n n n. For example, we have S ( 123 ) = 1 + 2 + 3 = 6 S(123)=1+2+3=6 S(123)=1+2+3=6.
Given two 3 3 3-digit integers A A A and B B B, find the greater of S ( A ) S(A) S(A) and S ( B ) S(B) S(B).

Input

Input is given from Standard Input in the following format:

A B

Output

Print the value of the greater of S ( A ) S(A) S(A) and S ( B ) S(B) S(B).
If these are equal, print S ( A ) S(A) S(A).

Sample 1

Sample Input 1

123 234

Sample Output 1

9

Explaination

We have S ( 123 ) = 1 + 2 + 3 = 6 S(123)=1+2+3=6 S(123)=1+2+3=6 and S ( 234 ) = 2 + 3 + 4 = 9 S(234)=2+3+4=9 S(234)=2+3+4=9, so we should print the greater of these: 9 9 9.

Sample 2

Sample Input 2

100 999

Sample Output 2

27

Constraints

  • All values in input are integers.
  • 100 ≤ A , B ≤ 999 100 ≤ A, B ≤ 999 100≤A,B≤999

题解报告

题目翻译

给一个整数 n n n,我们定义 S ( n ) S(n) S(n) 为 n n n 的每一位总和。比如, S ( 123 ) = 1 + 2 + 3 = 6 S(123)=1+2+3=6 S(123)=1+2+3=6。
给两个三位整数 A A A 和 B B B,找出更大的 S ( A ) S(A) S(A) 和 S ( B ) S(B) S(B)。

题目分析

还是老配方,一个签到题。当然本题不是最简单的语法签到题。本题的考点就是如何实现 S ( A ) S(A) S(A) 的功能,其实就是将任意数字的每一位取出。

S(A)

学习过 C + + C++ C++ 循环语法的,应该都可以实现。我们通过取模和整除功能,就可以实现。

int S(int a) {
	int ans=0;
	while (0!=a) {
		ans += a%10;
		a /= 10;
	}
	return ans;
}

当然本题非常的特殊,题目告诉我们,保证 A A A 和 B B B 是三位数字。因此可以直接使用取模加整除来实现。

int S(int a) {
	int gw = a%10;
	int sw = a/10%10;
	int bw = a/100%10;
	return gw+sw+bw;
}

数据规模分析

最大的三位数为 999 999 999,因此 S ( 999 ) = 9 + 9 + 9 = 27 S(999)=9+9+9=27 S(999)=9+9+9=27。用 int 足够。

AC 参考代码

//https://atcoder.jp/contests/abc187/tasks/abc187_a
//A - Large Digits 
#include <bits/stdc++.h>

using namespace std;

//如果提交到OJ,不要定义 __LOCAL
//#define __LOCAL

int sum(int x) {
    int ans=0;
    while (x) {
        ans+=x%10;
        x/=10;
    }
    return ans;
}

int main() {
#ifndef __LOCAL
    //这部分代码需要提交到OJ,本地调试不使用
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    int a,b;
    cin>>a>>b;

    //
    int ans0=sum(a);
    int ans1=sum(b);
    if (ans0>=ans1) {
        cout<<ans0<<"\n";
    } else {
        cout<<ans1<<"\n";
    }

#ifdef __LOCAL
    //这部分代码不需要提交到OJ,本地调试使用
    system("pause");
#endif
    return 0;
}

在这里插入图片描述

时间复杂度

O(1)。

空间复杂度

O(1)。

Oracle EBS Tax 四国实现详解:印度、巴西、美国、阿根廷 印度:务必启用India Localization模块,不要尝试用标准EBTax模拟GST逻辑 巴西:必须配置NF-e接口,建议聘请本地税务顾问设置CFOP和NCM代码映射 美国:跨州业务强烈建议购买Vertex或Avalara服务,自建税率表维护成本极高 阿根廷:注意1:1:1架构限制,提前规划Legal Entity和OU结构 阅读详情

相关推荐

从零到一:Ollama工具在RK3588上的深度优化实践

本文详细介绍了如何在RK3588开发板上深度优化Ollama工具,以高效运行DeepSeek模型。通过CPU与NPU负载平衡、模型量化、温度控制等策略,显著提升性能并降低功耗,适用于边缘计算场景。文章提供了具体的配置命令和优化方案,帮助开发者充分发挥RK3588的硬件潜力。

rgv23456789的博客 316

AtCoder题解 —— AtCoder Beginner Contest 187 —— D - Choose Me —— 贪心

题目相关 题目链接 AtCoder Beginner Contest 187 D 题,https://atcoder.jp/contests/abc187/tasks/abc187_d。 Problem Statement AtCoder City will hold a mayoral election. The candidates are Aoki and Takahashi. The city consists of NNN towns, the iii-th of which has AiA_iA

努力中的老周的专栏 774

电源设计之路-Buck电源环路设计(Type IIIA&Type IIIB)

在对Buck 环路补偿Type II拓扑进行仿真测试后,对瞬态波形以及伯德图已经有感官上的认知;然后再进一步对Type IIIA & IIIB进一步的学习;进一步了解Cout电容量和ESR对环路补偿的影响;认识到一个电源,不是参考Datasheet上的参数进行选值就行;更需要根据实际情况,功率电感值、输出电容值以及不同电容会有不一样的ESR,这些都会对环路参数产生一定的影响

2503_92839756的博客 767

AtCoder Beginner Contest 187 A~D题解

ABC187 A~D 题解 A - Large Digits B - Gentle Pairs C - 1-SAT D - Choose Me

天生我材必有用,千金散尽还复来。 8624

别再瞎试了!用Python+正交设计,5分钟搞定你的多因素实验方案

本文介绍了如何利用Python和正交设计高效优化多因素实验方案。正交设计通过精心设计的正交表,用最少的实验次数覆盖所有因素的水平组合,显著提升实验效率。文章详细讲解了正交设计的核心优势、Python实现工具链、实验实施与数据分析方法,以及高级技巧与常见问题解决方案,帮助读者快速掌握这一强大的实验优化技术。

weixin_42526087的博客 336

浅谈MOS管的发热原因和解决办法

解读一下开关管发热原因,解决方案和开关损耗测试。

qq_45508321的博客 1万+

AtCoder Beginner Contest 187F Close Group(状压dp)

https://atcoder.jp/contests/abc187/tasks/abc187_f 思路: 预处理完全图的思路就是先把每个点的可达集合都求出来,然后枚举每一个状态,找到该状态的一个点,判这个点的状态集是否包含了这个枚举的状态。即枚举的状态是这个点状态集的子集。 然后就可以状压dp了 注意位运算多加括号 #include<iostream> #include<vector> #include<queue> #include<cstring&

代码笔记本 347

基于虚拟阻抗重塑的构网型VSG变流器SISO序阻抗建模与宽频振荡抑制策略分析(面向高比例新能源并网场景)

本文深入探讨了基于虚拟阻抗控制的构网型VSG变流器SISO序阻抗建模技术及其在高比例新能源并网场景中的宽频振荡抑制策略。通过虚拟阻抗重塑,有效改善了变流器的阻抗特性,解决了次/超同步频段的振荡问题,并提供了参数设计、阻抗扫频验证等实用技巧,为新能源并网系统的稳定性提供了可靠解决方案。

weixin_29268385的博客 254

(Training 9)AtCoder Beginner Contest 187

A - Large Digits 给2个数 求出他们每一位的和比较大小并输出 #include<iostream> #include<algorithm> #include<cstring> using namespace std; const int N=1e5+10; int main(){ string a,b; cin>>a>>b; int ans1=0,ans2=0; for(int i=0;i<a.size();i++){

the_xin的博客 163

封装POD与PinMap文件总结学习-20250516

芯片封装外形图(POD)和PinMap是芯片设计和制造中的关键文档。POD详细描述了芯片的物理尺寸、引脚布局和封装类型,而PinMap则提供了芯片封装上各个引脚的位置、名称和功能的详细信息。这些文档在芯片设计、制造和应用过程中起到“地图”的作用,帮助设计人员理解芯片的物理和电气特性。在PCB设计中,POD用于确定socket的footprint和pogo的选型,而PinMap则用于器件的合理布局和布线。这些信息对于确保芯片的正确安装和功能至关重要。

歌颂苦难的行为是无耻的; 2389

(王道408考研数据结构)第八章排序-第一节:排序综述

文章目录一:排序一览二:简单插入排序(1)基本思想 一:排序一览 排序方法 类别 本文 时间复杂度 是否稳定 直接插入排序 插入排序 跳转 O(n2)O\left ( n^{2}\right )O(n2) 是 二叉树深度 简单 跳转 LeetCode 递归 翻转二叉树 简单 跳转 LeetCode 递归 相同的树 简单 跳转 LeetCode 递归 是否为子树 简单 跳转 LeetCode 递归 对称二叉树 简单 跳转 LeetCode 递归 平衡二叉树 简单 跳转

快乐江湖的博客 5494

AtCoder Beginner Contest 187 题解

A - Large Digits 按要求求出两个数的每位之和,进行比较即可。 时间复杂度 \(\mathcal{O}(\log(AB))\)。 B - Gentle Pairs 枚举所有点对求斜率。 时间复杂度 \(\mathcal{O}(N^2)\)。 int main() { ios_base::sync_with_stdio(false), cin.tie(0); int ...

橘嘉禾 79

Python爬虫实战——如何自动爬取百度搜索结果页面

本文介绍了如何使用Python爬虫抓取百度搜索结果页面的内容,包括如何构建搜索URL、获取页面HTML、解析内容、处理翻页以及存储数据等。通过该教程,您可以轻松实现批量抓取百度搜索结果,并为后续的数据分析和处理打下基础。希望本文能为您在爬虫开发、数据分析等领域提供帮助。如果您在实际应用过程中遇到问题,可以参考反爬虫应对策略,并结合实际需求进行调整。

2201_76125261的博客 1713

Atcoder Beginner Contest 187

Atcoder Beginner Contest 187

青少年趣味编程 657

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

AtCoder Beginner Contest 187

A - Large Digits 题意:求a,b两个数的数位和,比较之后输出最大的数位和。 思路: 模拟就好easy~ #include<bits/stdc++.h> using namespace std; int main() { int a,b,sum1=0,sum=0; cin>>a>>b; while(a!=0) { sum+=(a%10); a/=10; } while(b!=0) { sum1+=(b%10); b/=10;

RIPKEY的博客 361

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

AtCoder题解 —— AtCoder Beginner Contest 187 —— B - Gentle Pairs —— 暴力

题目相关 题目链接 AtCoder Beginner Contest 187 B 题,https://atcoder.jp/contests/abc187/tasks/abc187_b。 Problem Statement On the xyxyxy-plane, We have NNN points numbered 111 to NNN. Point iii is at (xi,yi)(x_i,y_i)(xi​,yi​), and the xxx-coordinates of the NNN point

努力中的老周的专栏 583

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

AtCoder ABC187

本期题比较简单,但是如果不懂套路就难以想到。

acrux1985的专栏 1039

AtCoder Beginner Contest 234 (D-F)

D、Prefix K-th Max 题目大意:给定一个长度为n的数组和一个k,对于每一个i(i >= k&&i <= n), 求前i个数字中第k大的数字是什么。 题解: 此题可以用优先队列来解决, 我们可以维护一个小根堆,然后维护其里面的size,一旦大于k则进行pop,这样的话每次输出答案时列头就是我们所需的答案,由于每个值只进来一次只出去一次,因此时间复杂度时O(nlogn) ! AC代码: #include <iostream> #include <a

m0_53430148的博客 829

c ++比较字符串是否相等_C ++程序检查字符串是否为回文

c ++比较字符串是否相等Here you will get C++ program to check string is palindrome or not. 在这里,您将获得C ++程序来检查字符串是否为回文。 A string is called palindrome if it is equal to its reverse. For example bob is string pal...

culing2941的博客 225

AtCoder Beginner Contest 187 F - Close Group

https://atcoder.jp/contests/abc187/tasks/abc187_f 有点像小米决赛的G题啊,所以就秒了 dp[i]表示i这个状压状态,最少可以是多少连通块组成 先预处理看这一个状态能不能用一个连通块,即全联通,那就枚举每个点看他与其他点有没有连上,可以预处理出每个点与哪些点相连了,然后用位运算O(1)判断 然后再枚举i的所有子集,看能不能合并 复杂度就是3^n #include<bits/stdc++.h> using namespace std;

binarycopycode 531

Codeforces Round #674 (Div. 3) ABCD 题解

A. Floor Number 题意:一开始的数为2,问加多少次x才能加到超过n。 思路:水题,循环一遍就行。 view code #include<iostream> #include<string> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #include<map> #include <queue> #in

待到山花烂漫时 536

AtCoder Beginner Contest 234

A - Weird Function 给出f函数表达式,求:f(f(f(t)+t)+f(f(t))) 签到题 重复利用的代码,最好写一个函数出来 #include <bits/stdc++.h> using namespace std; int f(int x) { return x * x + 2 * x + 3; } int main() { int t; cin >> t; int ans = 0; int ft = f(t);

m0_51508220的博客 753

AtCoder Beginner Contest 187 F.Close Group Editorial

AtCoder Beginner Contest 187 F.Close Group Editorial 题目链接 状压DP~ 如果对边暴力的话复杂度约为 21502^{150}2150,显然不可取,所以只能考虑对点集进行状压DP,设 VVV 为图的点集,SSS 为 VVV 的一个子集,dp[S]dp[S]dp[S] 表示此点集状态下的答案,那么我们可以推出状态转移方程: dp[S]={1,S是完全图min{dp[S],dp[T⊕S]+dp[T]},T⊆S dp[S]= \begin{cases} 1,S

旺崽的博客 2924

AtCoder Beginner Contest 055

A #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; int main(){ ll n; scanf("%lld", &n); printf("%lld\n", n * 800

傻傻分不清、 578

AtCoder Beginner Contest 234 题解

A、 题意明了不用思考直接模拟 #include<iostream> #include<algorithm> #include<cstring> using namespace std; typedef long long LL; LL cul(LL x) { return x*x+2*x+3; } int main() { LL n; scanf ("%lld",&n); printf ("%lld",cul(cul(cul(n)+n)+cul(cul(

MH3709的博客 843

AtCoder Beginner Contest 234题解(A~D)

AtCoder Beginner Contest 234题解(A~D)

涛涛的个人博客 998
上一篇: AtCoder题解 —— AtCoder Beginner Contest 187 —— B - Gentle Pairs —— 暴力
下一篇: AtCoder题解 —— AtCoder Beginner Contest 187 —— D - Choose Me —— 贪心
努力的老周
博客等级 码龄20年 1720粉丝 548原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

努力的老周

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址