Codeforces Round #244 (Div. 2) E. Police Patrol(数学)
来源:互联网 发布:手机桌面便签软件 编辑:程序博客网 时间:2024/05/22 04:48
题目地址:http://codeforces.com/problemset/problem/427/E
思路:显然,位置选在所有数的中位数时距离最短。则从两头取,累计和即可。
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;typedef long long LL;const int maxn=1e6+50;LL ans;int n,m;int a[maxn];int main(){ scanf("%d%d",&n,&m); for(int i=1; i<=n; i++) scanf("%d",&a[i]); int p=n/2+1; for(int i=1; i<=p; i+=m) ans+=abs(a[i]-a[p]); for(int i=n; i>p; i-=m) ans+=abs(a[i]-a[p]); printf("%I64d\n",ans*2); return 0;}
0 0
- Codeforces Round #244 (Div. 2) E. Police Patrol(数学)
- Codeforces Round #244 (Div. 2)E. Police Patrol
- Codeforces Round #244 (Div. 2) E. Police Patrol
- Codeforces Round #244 (Div. 2) E. Police Patrol
- Codeforces 427E Police Patrol
- Codeforces 427E. Police Patrol
- Codeforces #427 E题Police Patrol(三分查找)
- Codeforces Round #244 (Div. 2)a Police Recruits
- Codeforces Round #408 (Div. 2) -- D. Police Stations(bfs)
- Codeforces Round #281 (Div. 2)E(数学)
- codeforces Police Patrol
- Codeforces Round #130 (Div. 2) C. Police Station
- Codeforces Round #408 (Div. 2) D.Police Stations【Bfs+思维】
- Codeforces Round #408 (Div. 2) D. Police Stations
- Codeforces Round #408 (Div. 2)-D. Police Stations
- Codeforces Round #408 (Div. 2) D.Police Stations【Bfs+思维】
- Codeforces Round #265 (Div. 2)E. Substitutes in Number(数学)
- Codeforces Round #244 (Div. 2)——A. Police Recruits(水)
- 无向图的领接表
- Eclipse 部分常见快捷键
- python之强大的日志模块
- Git diff ^M的消除
- Multiplication Table
- Codeforces Round #244 (Div. 2) E. Police Patrol(数学)
- 阿里云oss存储使用sts时的后台处理逻辑
- python 标准异常
- 制作uboot
- 五、Nginx反向代理
- 习题29 if语句
- sql server 查看表的死锁和Kill 死锁进程
- 同时抓取带时间的logcat和kernel log的方法
- SQL高级查询——50句查询(含答案)