【CS Round #37 (Div. 2 only) A】Boring Number
【Link】:https://csacademy.com/contest/round-37/task/boring-number/
【Description】
让你找离平均数最近的一个数的下标;
【Solution】
判断的时候,平均数和枚举的数都乘上n;
这样精度比较高;避免小数比较;
【NumberOf WA】
0
【Reviw】
empty
【Code】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e3;
int a[N+100],n,sum,mi,idx;
int main(){
//Open();
//Close();
scanf("%d",&n);
rep1(i,1,n){
scanf("%d",&a[i]);
sum+=a[i];
}
mi = abs(sum-a[1]*n),idx = 1;
rep1(i,2,n){
int temp = abs(sum-a[i]*n);
if (temp < mi){
mi = temp;
idx = i;
}
}
cout << idx << endl;
return 0;
}
/*
写完之后,明确每一步的作用
*/
【CS Round #37 (Div. 2 only) A】Boring Number的更多相关文章
- 【CS Round #37 (Div. 2 only) D】Reconstruct Graph
[Link]:https://csacademy.com/contest/round-37/task/reconstruct-graph/statement/ [Description] 给你一张图; ...
- 【CS Round #37 (Div. 2 only) B】Group Split
[Link]:https://csacademy.com/contest/round-37/task/group-split/ [Description] 让你把一个数分成两个数a.b的和; (a,b ...
- 【CS Round #36 (Div. 2 only) A】Bicycle Rental
[题目链接]:https://csacademy.com/contest/round-36/task/bicycle-rental/ [题意] 让你从n辆车中选一辆车; 每一辆车有3个属性 1.到达车 ...
- 【CS Round #39 (Div. 2 only) D】Seven-segment Display
[Link]:https://csacademy.com/contest/round-39/task/seven-segment-display/ [Description] 0..9各自有一个数字, ...
- 【CS Round #39 (Div. 2 only) C】Reconstruct Sum
[Link]:https://csacademy.com/contest/round-39/task/reconstruct-sum/ [Description] 给你一个数字S; 让你找有多少对A, ...
- 【CS Round #39 (Div. 2 only) B】Circle Elimination
[Link]:https://csacademy.com/contest/round-39/task/circle-elimination/ [Description] [Solution] 把n个点 ...
- 【CS Round #39 (Div. 2 only) A】Removed Pages
[Link]: [Description] [Solution] 每读入一个x; 把a[(x-1)/2]置为1即可; 统计1的个数 [NumberOf WA] [Reviw] [Code] /* */ ...
- 【CS Round #46 (Div. 1.5) E】Ultimate Orbs
[链接]链接 [题意] n个人从左到右站在一条直线上.每个人都有一个能力值g[i],然后每个人可以将相邻的一个人打败. 然后它的能力值能够增加相应的能力值(就是打败了的那个人的能力值). A能够打败B ...
- 【CS Round #46 (Div. 1.5) C】Set Subtraction
[链接]h在这里写链接 [题意] 一开始有n个数字,然后有一个数字X,把每个数字都减去X,又生成N个新的数字. 然后把这2*N个数字混在一起. 告诉你这2*N个数字是什么.让你复原出原来的N个数字,以 ...
随机推荐
- 芒果TV真实视频地址解析
本文旨在互相学习,请勿滥用 若有幸被您引用请附加地址来源http://blog.csdn.net/feige2008/article/details/37579051 文章主要解析芒果TV的视频真实地 ...
- php冒泡排序函数
$arr=array(23,5,26,4,9,85,10,2,55,44,21,39,11,16,55,88,421,226,588); function maopao($arr,$value){// ...
- 如何解读「量子计算应对大数据挑战:中国科大首次实现量子机器学习算法」?——是KNN算法吗?
作者:知乎用户链接:https://www.zhihu.com/question/29187952/answer/48519630 我居然今天才看到这个问题,天……本专业,有幸听过他们这个实验的组会来 ...
- LeetCode SQL
SQL查询练习一(From LeetCode) 1 select name,population,area 2 from World 3 where area > 3000000 or popu ...
- rest_framework-版本-总结完结篇
总urls.py from django.conf.urls import url, include urlpatterns = [ url(r'^api/', include('api.urls') ...
- <Sicily>Greatest Common Divisors
一.题目描述 A common divisor for two positive numbers is a number which both numbers are divisible by. It ...
- MPP的进化 - 深入理解Batch和MPP优缺点
https://mp.weixin.qq.com/s/scXNfkpjktCZxBg3pYEUUA?utm_medium=hao.caibaojian.com&utm_source=hao.c ...
- 1、Go base64编码
package main import ( "encoding/base64" "fmt") func main() { //标准base64编码 data:= ...
- ubuntu 18.04网卡命名规则改回传统的ethx
自15版本开始网卡命名规则就不叫eth0了.而是用可预期网络接口设备名称的命名规则,比如网卡名为enp3s0 . 如果想要变回ethx也是可以的,参考以下步骤: 1.编辑/etc/default/gr ...
- Linux Putty 复制粘贴
从putty复制: 用左键选中文字,再其他地方点中键就可以粘贴了,不需要右键粘贴. 在putty中粘贴: 在其他地方用左键选中文字,不用右键复制,保持选中文字高亮,然后在putty中点中键 ...