Salem and Sticks
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相关推荐
- 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_A. Salem and Sticks_数组/暴力
A. Salem and Sticks time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Salem and Sticks-萨鲁曼的棍子 CodeForce#1105A 暴力
题目链接:Salem and Sticks 题目原文 Salem gave you ?n sticks with integer positive lengths ?1,?2,-,??a1,a2,-, ...
- 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 ...
- HDU1051Wooden Sticks
Wooden Sticks http://acm.hdu.edu.cn/showproblem.php?pid=1051 #include<stdio.h> struct stick{ i ...
- UVa307 - Sticks(DFS+剪枝)
题意:给出若干个一样长的sticks,剪断后有n个部分,问原来sticks的最小长度. 思路:首先要确定sticks的长度范围,范围应该在[max(n1,n2..., n), sum(n1,n2... ...
- HDU-1051 Wooden Sticks
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 欧拉路径 之 poj 2513 Colored Sticks
/* 欧拉路径 之 poj 2513 Colored Sticks欧拉路径: 若图G中存在这样一条路径,使得它恰通过G中每条边一次,则称该路径为欧拉路径.无向图存在欧拉路径 充要条件:1) 图是连通的 ...
- 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 ...
最新文章
- JQuery $post函数
- 库克在白宫网络峰会中再次反对加密后门
- java mysql访问类_java 访问数据库公共类
- lcase和ucase_在SQL中使用UCASE(),LCASE()和MID()函数
- python黑色背景_如何去除Matplotlib图中的黑色背景
- gitlab 修改存储为mysql_gitlab仓库存储位置的修改方法
- C语言:判断三角形是否为直角三角形
- 利用pandas处理二级office的Excel试题(一)
- windows 下 c++ 二维码生成库
- jvm-虚拟机栈笔记【详细】
- cocos2dx_lua读取unity手机游戏本地文件
- phabricator 结合 arcanist 使用
- 【译】Vertical-Align: All You Need To Know
- 骨传导耳机工作原理是什么、为什么骨传导耳机塞住耳朵声音变大?
- 算法提高 盾神与积木游戏
- 斯坦福SCI论文写作课笔记(十)
- 三种方法进行图片锐化
- HDOJ 2112 HDU Today (最短路 Dijkstra SPFA)
- 【论文笔记】 知识图谱 之 TransE算法(Translating Embedding)
- 用electron做一个浏览器