当前位置:网站首页>ACWing春季每日一题——你知道ABC吗
ACWing春季每日一题——你知道ABC吗
2022-04-23 00:29:00 【Soraku7】
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 7;
int main()
{
int all[N];
int A, B ,C;
for (int i = 0; i < N; i ++ ){
cin >> all[i];
}
sort(all,all + 7);
A = all[0];
B = all[1];
C = all[6] - A - B;
cout << A <<" " << B << " "<< C;
return 0;
}
这道题目本身是一道数学题,
已知A <= B <= C,其中所有的数为A、B、C、A+B、B+C、C+A 和 A+B+C
这里我们不难发现如果将所有的数进行排序,那么A一定是最小的数 , A + B + C一定是最大的数。
现在难点来了,我们现在知道A + B , B + C , A + C一定是大于A的,现在我们可以试着推测一下B所在的顺序。
假设B所在的位置是第三位,那么其中的第二位数肯定不是C(C >= B),
再者 B一定是小于 A + B , B + C , A + C.所以第二位数也一定不是这三个数
A + B + C是最大的数 , 所以我们不难看出(第二位没有位置放数字),B在已排序的数组在第三位是不存在这种情况的
所以B现在也不可能放到数组的更大的位置了, 所以我们可知 B现在有两种情况;
1、B和C相等
2、B小于C
所以可知B的值一定是等于在第二位的。
现在我们相当于知道了A 知道了B , 知道了A + B + C 所以剩下的的C就非常容易求得了
这里的sort是C++的排序, (当然初学C语言的同学可以自己手写一个排序)
版权声明
本文为[Soraku7]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Solaku7/article/details/124219187
边栏推荐
- ArcMap uses drawing tools to add annotations
- ArcGIS urban living area land suitability evaluation (IV)
- cluster_ ACC calculation
- EXCEL IF函数的简单使用
- 【图像分类】 一文读懂AlexNet
- [image classification] understand Alex net
- 2022年4月22日,第15天
- MySQL -- database foundation
- Solution for error reporting of biff el6631 and Siemens communication PROFINET
- Dialogue with Yang jiongwei, fast is reflected in seizing the "bonus". In fact, tob company should run slower
猜你喜欢

Nodejs learning notes

【AI视野·今日Sound 声学论文速览 第四期】Thu, 21 Apr 2022

倍福NC轴走速度模式

MySQL installation and basic use tutorial

(transfer) how winscp (SSH FTP client) generates the key to log in Linu

【征文大赛】TiDB 社区专栏第一届征文大赛,快来一次性集齐所有周边吧!

将 AWS S3 数据迁移至 TiDB Cloud 集群

Antd design pro uses Baidu map, which can be tested in person

我和TiDB的故事 | 毫无准备地不期而遇,却想说与你相遇好幸运

(转)通过RDP隧道绕过网络限制
随机推荐
(转)C#最佳工具集合:IDE、分析、自动化工具等
Componentwillunmount uninstall components
Node + mongoose paging effect
Application of tidb in massive transactions and real-time analysis of fast food chain enterprises
ArcGIS 城市生活区用地适宜性评价(三)
(转)WinSCP(SSH的FTP客户端)如何生成密钥登陆linu
倍福Scaling factor因子计算
MySQL运行workbench报错TRunTimeError
Ads communication between two CX controllers of Beifu TwinCAT
Configuration parameters of common product module models of Beifu
(transfer) how winscp (SSH FTP client) generates the key to log in Linu
Installing MySQL in centos7
(转)Matlab R2014a 64位与Visual Studio2015的mex相关问题
Progrès de la recherche sur la télédétection des paramètres phénologiques de la végétation
倍福EL6631和西门子1200做Profinet主从通信
Calculation of Beifu scaling factor
(transfer) matlab r2014a 64 bit and mex related problems of visual studio 2015
(to) excel 2016 does not have enough memory or disk space to open excel
Migrate AWS S3 data to tidb cloud cluster
Dynamic programming: grouping knapsack problem