Codeforces Round #533 (Div. 2) A. Salem and Sticks(枚举)
#include <bits/stdc++.h>
using namespace std; int main()
{
int n;cin>>n;
int a[n];for(int &i:a) cin>>i;
int ans_ave=0,ans_cost=INT_MAX;
for(int i=1;i<=100;i++){
int ave=i,cost=0;
for(int j:a){
if(j<i) cost+=i-1-j;
else if(j>i) cost+=j-i-1;
}
if(cost<ans_cost)
ans_ave=ave,ans_cost=cost;
}
cout<<ans_ave<<' '<<ans_cost;
return 0;
}
Codeforces Round #533 (Div. 2) A. Salem and Sticks(枚举)的更多相关文章
- Codeforces Round #533 (Div. 2) A. Salem and Sticks(暴力)
A. Salem and Sticks time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #533(Div. 2) A.Salem and Sticks
链接:https://codeforces.com/contest/1105/problem/A 题意: 给n个数,找到一个数t使i(1-n)∑|ai-t| 最小. ai-t 差距1 以内都满足 思路 ...
- Codeforces Round #533 (Div. 2)题解
link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...
- Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心
Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks
题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...
- Codeforces Round #533 (Div. 2) Solution
A. Salem and Sticks 签. #include <bits/stdc++.h> using namespace std; #define N 1010 int n, a[N ...
- Codeforces Round #533 (Div. 2) 部分题解A~D
A. Salem and Sticks 题目描述 Salem gave you n n n sticks with integer positive lengths a1,a2,…,an a_1, a ...
- Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS
题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...
- Codeforces Round #533 (Div. 2) C. Ayoub and Lost Array 【dp】
传送门:http://codeforces.com/contest/1105/problem/C C. Ayoub and Lost Array time limit per test 1 secon ...
随机推荐
- JVM故障处理工具,使用总结
作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 用都用不到怎么学? 没有场景.没有诉求,怎么学习这些似乎用不上知识点. 其实最好的方 ...
- 非root用户安装centos的jdk
1. 下载linux的jdk到自定义目录(以下简称安装目录),解压. 2. 在安装目录下新建文件局部环境变量文件:bash_profile 内容为:(注意修改JAVA_HOME目录) export J ...
- 【SpringMVC】SpringMVC 拦截器
SpringMVC 拦截器 文章源码 拦截器的作用 SpringMVC 的处理器拦截器类似于 Servlet 开发中的过滤器 Filter,用于对处理器进行预处理和后处理. 谈到拦截器,还有另外一个概 ...
- Linux find 命令的初步实现(C++)
Implement a myfind command following the find command in UNIX operating system. The myfind command s ...
- 简单解析一下 Mybatis 常用的几个配置
目录 核心配置文件 环境配置(environments) 属性(properties) 类型别名(typeAliases) 映射器(mappers) Mybatis 参考:https://mybati ...
- 【Linux】CentOS7中yumbackend.py进程的结束方法
环境: CentOS Linux release 7.3.1611 (Core) 今天启动这个不怎么用的机器,才启动,就发现后台的yum无法进行安装,持续报这个错误 Loaded plugins: f ...
- linux中进制转换
方式一:使用$[]或$(()) 格式为:$[base#number]或$((base#number)),其中base为进制,number为对应进制数. 这种方式输入2进制.16进制等,但只能输出为10 ...
- springboot项目启动并立即执行自定义程序内容
第一种:实现ApplicationRunner接口,重写其中的run()方法: 第二种:实现CommandLineRunner接口,重写其中的run()方法: 还有第三种...
- MySQL增删改操作
增删改操作 增加 看语法 1. 插入完整数据(顺序插入) 语法一: INSERT INTO 表名(字段1,字段2,字段3-字段n) VALUES(值1,值2,值3-值n); #指定字段来插入数据,插入 ...
- 扩展:Flash消息
扩展:Flash消息 flash存值之后只能取一次 from flask import Flask,render_template,flash,get_flashed_messages,session ...