https://codeforces.com/contest/1105/problem/A

题解:数据较小暴力就行了

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
int ans,cnt,flag,temp;
int a[N];
char str;
int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endifscanf("%d",&n);//scanf("%d",&t);//while(t--){}for(int i=1;i<=n;i++){scanf("%d",&a[i]);}sort(a+1,a+n+1);ans=INF;for(int i=a[1];i<=a[n];i++){cnt=0;for(int j=1;j<=n;j++){if(a[j]<i-1)cnt+=abs(i-1-a[j]);if(a[j]>i+1)cnt+=abs(i+1-a[j]);}if(ans>cnt){ans=cnt;flag=i;}}cout<<flag<<" "<<ans<<endl;//cout << "Hello world!" << endl;return 0;
}

Salem and Sticks相关推荐

  1. 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 以内都满足 思路 ...

  2. codeforces_A. Salem and Sticks_数组/暴力

    A. Salem and Sticks time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. Salem and Sticks-萨鲁曼的棍子 CodeForce#1105A 暴力

    题目链接:Salem and Sticks 题目原文 Salem gave you ?n sticks with integer positive lengths ?1,?2,-,??a1,a2,-, ...

  4. 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 ...

  5. HDU1051Wooden Sticks

    Wooden Sticks http://acm.hdu.edu.cn/showproblem.php?pid=1051 #include<stdio.h> struct stick{ i ...

  6. UVa307 - Sticks(DFS+剪枝)

    题意:给出若干个一样长的sticks,剪断后有n个部分,问原来sticks的最小长度. 思路:首先要确定sticks的长度范围,范围应该在[max(n1,n2..., n), sum(n1,n2... ...

  7. HDU-1051 Wooden Sticks

    Wooden Sticks       Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  8. 欧拉路径 之 poj 2513 Colored Sticks

    /* 欧拉路径 之 poj 2513 Colored Sticks欧拉路径: 若图G中存在这样一条路径,使得它恰通过G中每条边一次,则称该路径为欧拉路径.无向图存在欧拉路径 充要条件:1) 图是连通的 ...

  9. 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 MB Submit: xxx ...

最新文章

  1. JQuery $post函数
  2. 库克在白宫网络峰会中再次反对加密后门
  3. java mysql访问类_java 访问数据库公共类
  4. lcase和ucase_在SQL中使用UCASE(),LCASE()和MID()函数
  5. python黑色背景_如何去除Matplotlib图中的黑色背景
  6. gitlab 修改存储为mysql_gitlab仓库存储位置的修改方法
  7. C语言:判断三角形是否为直角三角形
  8. 利用pandas处理二级office的Excel试题(一)
  9. windows 下 c++ 二维码生成库
  10. jvm-虚拟机栈笔记【详细】
  11. cocos2dx_lua读取unity手机游戏本地文件
  12. phabricator 结合 arcanist 使用
  13. 【译】Vertical-Align: All You Need To Know
  14. 骨传导耳机工作原理是什么、为什么骨传导耳机塞住耳朵声音变大?
  15. 算法提高 盾神与积木游戏
  16. 斯坦福SCI论文写作课笔记(十)
  17. 三种方法进行图片锐化
  18. HDOJ 2112 HDU Today (最短路 Dijkstra SPFA)
  19. 【论文笔记】 知识图谱 之 TransE算法(Translating Embedding)
  20. 用electron做一个浏览器

热门文章

  1. python矩阵行秩函数_为什么矩阵行秩等于列秩?
  2. 如何使一台计算机可以在互联网上访问到
  3. 战神背光键盘如何关系_4000元学生办公游戏本该如何选择?
  4. 8类网线利弊_超6类网线和7类网线有何区别?有何用途?家用电脑,看这
  5. 三十四、多线程真的比单线程快?
  6. myFocus制作焦点图
  7. 一块V100运行上千个智能体、数千个环境,这个曲率引擎框架实现RL百倍提速
  8. 线性Transformer应该不是你要等的那个模型
  9. SIGIR 2021|重新思考Attention在CTR预估中作用
  10. 百度PARL再度夺冠NeurIPS仿生人挑战赛:强化学习控制的流畅行走