CF134A Average Numbers 题解
Content
有 \(n\) 个数 \(a_1,a_2,a_3,...,a_n\)。试求出使得 \(a_i\) 与其他所有整数的算术平均值相等的所有 \(i\)。
数据范围:\(2\leqslant n\leqslant 2\times10^5,1\leqslant a_i\leqslant 1000\)。
Solution
我们可以将其转化为:求出能满足 \(a_i=\dfrac{\sum\limits_{j=1}^na_j-a_i}{n-1}\) 的所有 \(i\)。直接在数列中扫一遍看能不能满足这个条件即可。注意精度问题,需要将 \(a_i\) 开成高精度的 \(\texttt{double}\)。
Code
#include <cstdio>
#include <algorithm>
using namespace std;
int n, ans[200007];
double s, a[200007];
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
scanf("%lf", &a[i]);
s += a[i];
}
for(int i = 1; i <= n; ++i)
if(a[i] == (s - a[i]) / (n - 1)) ans[++ans[0]] = i;
for(int i = 0; i <= ans[0]; ++i) {
printf("%d", ans[i]);
if(!i) puts("");
else printf(" ");
}
return 0;
}
CF134A Average Numbers 题解的更多相关文章
- CF55D Beautiful numbers 题解
题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...
- Hdoj 1905.Pseudoprime numbers 题解
Problem Description Fermat's theorem states that for any prime number p and for any integer a > 1 ...
- Hdoj 1058.Humble Numbers 题解
Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The ...
- [LeetCode] Add Two Numbers题解
Add Two Numbers: You are given two non-empty linked lists representing two non-negative integers. Th ...
- poj 1995 Raising Modulo Numbers 题解
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6347 Accepted: ...
- CF1265B Beautiful Numbers 题解
Content 给定一个 \(1\sim n\) 的排列,请求出对于 \(1\leqslant m\leqslant n\),是否存在一个区间满足这个区间是一个 \(1\sim m\) 的排列. 数据 ...
- CF1157A-Reachable Numbers题解
原题地址 题目大意:有一个函数\(f(x)\),效果是将\(x+1\)后,去掉末尾所有的\(0\),例如: \(f(599)=6\),因为\(599+1=600→60→6\) \(f(7)=8\),因 ...
- CF359D:Pair of Numbers——题解
https://vjudge.net/problem/CodeForces-359D http://codeforces.com/problemset/problem/359/D 题目大意: 给一串数 ...
- Timus : 1002. Phone Numbers 题解
把电话号码转换成为词典中能够记忆的的单词的组合,找到最短的组合. 我这道题应用到的知识点: 1 Trie数据结构 2 map的应用 3 动态规划法Word Break的知识 4 递归剪枝法 思路: 1 ...
随机推荐
- .NET Core 3.0 JsonSerializer.Deserialize 返回dynamic类型对象
.NET Core 3.0 JsonSerializer.Deserialize to dynamic object 因为官方还不支持返回动态类型的对象,只能自己手写一个,临时测试了下没问题,还有些地 ...
- c语言用指针交换两个变量
#include<stdio.h> #include<math.h> int main(){ void swap(int a,int b); void swapPointer( ...
- CF1578J Just Kingdom
考虑一个点被填满则他需要从其父亲得到\(q_u = \sum_{v = u\ or\ v \in son_u}m_v\) 那么考虑如何这样操作. 我当时world final做的时候,是从上往下遍历, ...
- CF1264D1 Beautiful Bracket Sequence (easy version)
考虑在一个确定的括号序列中,我们可以枚举中间位置,按左右最长延伸出去的答案计算. 我们很自然的思考,我们直接维护左右两边,在删除一些字符后能够延伸的最长长度. 我们设\(f_{i,j}\)为\(i\) ...
- [yLOI2018] 锦鲤抄
先思考图上是\(tag\)的特殊情况. 考虑我们按拓扑序反过来操作,就可以得到我们任意想要的顺序. 那么我们把所有的图都缩点操作,那么我们只需要考虑一个联通分量里就行了. 一个联通分量最后只会剩下一个 ...
- 【2020五校联考NOIP #6】三格缩进
题意: 给出 \(n\) 个数 \(a_1,a_2,\dots,a_n\),你要进行 \(m\) 次操作,每次操作有两种类型: \(1\ p\ x\):将 \(a_p\) 改为 \(x\). \(2\ ...
- 洛谷 P3438 - [POI2006]ZAB-Frogs(乱搞/李超线段树)
题面传送门 首先一眼二分答案,我们假设距离 \((i,j)\) 最近的 scarefrog 离它的距离为 \(mn_{i,j}\),那么当我们二分到 \(mid\) 时我们显然只能经过 \(mn_{i ...
- 【Python小试】计算蛋白序列中指定氨基酸所占的比例
编码 from __future__ import division def get_aa_percentage(protein, aa_list=['A','I','L','M','F','W',' ...
- dlang 安装
刷论坛看到TIOBE排行榜,排名靠前的基本是C.C++.java.python之类的语言,常用的R语言近几年排名一路走高,前20基本变化不大. 后面发现第二十九位居然有个叫做D的语言,看了下和C语法很 ...
- phpMyAdmin简介及安装
phpMyAdmin是一个MySQL数据库管理工具,通过Web接口管理数据库方便快捷. Linux系统安装phpMyAdmin phpMyAdmin是一个MySQL数据库管理工具,通过Web接口管理数 ...