博客
关于我
2018蓝桥杯C++A组——付账问题
阅读量:111 次
发布时间:2019-02-26

本文共 772 字,大约阅读时间需要 2 分钟。

目录

问题描述

【题目描述】

在这里插入图片描述
s = 1 n ∑ i = 1 n ( b i − 1 n ∑ i = 1 n b i ) 2 s=\sqrt{\frac{1}{n}\sum_{i=1}^{n}\left ( b_i-\frac{1}{n}\sum_{i=1}^{n}b_i \right )^2} s=n1i=1n(bin1i=1nbi)2

【输入】

在这里插入图片描述
【输出】
在这里插入图片描述
【样例输入】

5 2333666 666 666 666 666

【样例输出】

0.0000

题目解析

我们可以简单分析一下,若能让每个人在够付账的情况下付的金额尽可能集中就可以使得标准差最小。

举个例子假如 n = 10 , S = 30 n=10,S=30 n=10,S=30,每个人金额分别为 1 , 2 , 3 , 4 , 4 , 4 , 6 , 7 , 7 , 8 1,2,3,4,4,4,6,7,7,8 1,2,3,4,4,4,6,7,7,8,先求出均值 a v g = 4.6 avg=4.6 avg=4.6,再对金额进行排序。

  1. 当金额小于均值时需要付出所有的钱;
  2. 当金额大于或等于均值时,这个人以及之后的所有人都需要在第一步完成的基础上重新计算均值即为 c u r _ a v g cur\_avg cur_avg

C++代码

#include
using namespace std;typedef long long LL;int n;LL S;double ans,avg;void work(){ scanf("%d %lld",&n,&S); ans = 0.0; avg = 1.0*S/n; //总平均值 LL *a = new LL[n]; //存储数据 for(int i=0;i

结果

在这里插入图片描述

转载地址:http://swqu.baihongyu.com/

你可能感兴趣的文章
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No static resource favicon.ico.
查看>>
no such file or directory AndroidManifest.xml
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>
no1
查看>>
NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
查看>>
NOAA(美国海洋和大气管理局)气象数据获取与POI点数据获取
查看>>
NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
查看>>