当前位置:网站首页>Translation D28 (with AC code POJ 26:the nearest number)
Translation D28 (with AC code POJ 26:the nearest number)
2022-07-06 19:16:00 【Ctrl AC】
“ Ctrl AC! Together AC!”
The original title is :The Nearest Number
My translation :
describe
Given N Sequence and number of numbers K. stay (X subtract K) Find the nearest number in the sequence with the smallest absolute value of X.
Input
first line : Two positive integers N(N<=100) and K(K<=100000). The second line :N A positive integer (<=100000).
Output
An integer X.
AC Code :
include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;cin>>n>>k;
int minn=0x3f3f3f3f;
int ans=-1;
for(int i=0;i<n;i++){
int num;cin>>num;
if(abs(num-k)<minn){
ans=num;
minn=abs(num-k);
}
}
cout<<ans<<endl;
return 0;
}
Thank you for reading !!!
“ Ctrl AC! Together AC!”
边栏推荐
- Openmv4 learning notes 1 --- one click download, background knowledge of image processing, lab brightness contrast
- The nearest library of Qinglong panel
- R language uses DT function to generate t-distribution density function data and plot function to visualize t-distribution density function data
- 中缀表达式转后缀表达式详细思路及代码实现
- Online notes
- Precautions for binding shortcut keys of QPushButton
- English topic assignment (25)
- The second day of rhcsa study
- 包装行业商业供应链管理平台解决方案:布局智慧供应体系,数字化整合包装行业供应链
- Video based full link Intelligent Cloud? This article explains in detail what Alibaba cloud video cloud "intelligent media production" is
猜你喜欢
Lucun smart sprint technology innovation board: annual revenue of 400million, proposed to raise 700million
The second day of rhcsa study
Yutai micro rushes to the scientific innovation board: Huawei and Xiaomi fund are shareholders to raise 1.3 billion
Optical blood pressure estimation based on PPG and FFT neural network [translation]
Dark horse -- redis
Graffiti intelligence is listed on the dual main board in Hong Kong: market value of 11.2 billion Hong Kong, with an annual revenue of 300 million US dollars
[matlab] Simulink the input and output variables of the same module cannot have the same name
快速幂模板求逆元,逆元的作用以及例题【第20届上海大学程序设计联赛夏季赛】排列计数
MRO industrial products enterprise procurement system: how to refine procurement collaborative management? Industrial products enterprises that want to upgrade must see!
裕太微冲刺科创板:拟募资13亿 华为与小米基金是股东
随机推荐
MATLAB中deg2rad和rad2deg函数的使用
R语言使用order函数对dataframe数据进行排序、基于单个字段(变量)进行降序排序(DESCENDING)
Don't miss this underestimated movie because of controversy!
CCNP Part 11 BGP (III) (essence)
Precautions for binding shortcut keys of QPushButton
R language ggplot2 visualization: use the ggdotplot function of ggpubr package to visualize dot plot, set the palette parameter, and set the colors of data points and box graphs of dot plots at differ
R语言ggplot2可视化:使用ggpubr包的ggdotplot函数可视化点阵图(dot plot)、设置palette参数设置不同水平点阵图数据点和箱图的颜色
tensorflow和torch代码验证cuda是否安装成功
Digital "new" operation and maintenance of energy industry
Pychrm Community Edition calls matplotlib pyplot. Solution of imshow() function image not popping up
Simple understanding of MySQL database
Online notes
Tongyu Xincai rushes to Shenzhen Stock Exchange: the annual revenue is 947million Zhang Chi and Su Shiguo are the actual controllers
R语言dplyr包进行数据分组聚合统计变换(Aggregating transforms)、计算dataframe数据的分组均值(mean)
R语言ggplot2可视化:使用ggpubr包的ggstripchart函数可视化分组点状条带图(dot strip plot)、设置add参数为不同水平点状条带图添加箱图
业务与应用同步发展:应用现代化的策略建议
Use map function and split function to type multiple elements in one line
中缀表达式转后缀表达式详细思路及代码实现
Based on butterfly species recognition
倒计时2天|腾讯云消息队列数据接入平台(Data Import Platform)直播预告