当前位置:网站首页>*2-3 Upgraded version of OJ 1164 missile interceptor
*2-3 Upgraded version of OJ 1164 missile interceptor
2022-08-09 14:51:00 【Leaf Xiao Bai】
题目描述

输入

输出

样例输入

样例输出

源代码
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
int n,i;
while(scanf("%d",&n)!=EOF)
{
int a[1000];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
int min=n*a[0],s=0,r=a[0];
for(i=0;i<n;i++)
{
s=s+a[i];
if(a[i]*n-s<=min)
{
min=a[i]*n-s;
r=a[i];
}
}
printf("%d\r\n",r);
}
return 0;
}
关于这题
语法
Sort(start,end,cmp)
参数
(1)start表示要排序数组的起始地址;
(2)end表示数组结束地址的下一位;
(3)cmp用于规定排序的方法,可不填,默认升序.
头文件
#include algorithm(c++)
This question requires When the cost of use is minimal Sets the value of the working radius
(如果有多个 取最大值)
我们使用sort 进行升序排序 这里a[i]*n-s<=min 取等号 The result obtained here is the maximum working radius
min 为最小代价 rThe size of the radius at this time
s is the sum of the distances of intercepted missiles
Start with the smallest interception Calculate usage cost 与min 比较 把minbecome the minimum cost
边栏推荐
- GridContainer of openharmony container component
- #25-1 OJ 78 计算生日星期几
- C语言 交换两个变量(不创建临时变量) 代码详解
- RHCE课程总结
- 使用 compose 的 Canvas 自定义绘制实现 LCD 显示数字效果
- The code implementation of chess
- display:inline-block 什么时候不会显示间隙?
- Es7.x使用RestHighLevelClient进行增删改和批量操作
- 蓝桥杯嵌入式(STM32F103RBT6)最全攻略(一)
- [Video coding learning] - understanding of transformation
猜你喜欢
随机推荐
Jetpack Compose - remember, mutableStateOf, rememberSaveable
阿里巴巴云原生大数据运维平台 SREWorks 正式开源
C语言 最大公约数,最小公倍数(详细注释代码 一次解决)
How to develop small programs?should focus on features
RHCE课程总结
LNMP架构搭建之论坛
汇编语言学习(九)
小程序制作软件哪个好用?如何选择?
RHCE Course Summary
Difference between apt-get install and pip install
The code implementation of chess
大规模并行分布式深度学习
汇编语言学习(八)
*5-2 CCF 2014-12-3 集合竞价
*1-4 OJ 605 格雷码
C语言 函数问题
Analysis of SEATA Distributed Transaction Framework
RHCE课程总结
display:inline-block 什么时候不会显示间隙?
iptables之SNAT与DNAT









