Codeforces Round 421 Div.2 D. Mister B and PR Shifts 思维 乱搞
来源:互联网 发布:cf鬼跳宏数据 编辑:程序博客网 时间:2024/05/29 04:32
题目地址:
http://codeforces.com/contest/820/problem/D
题意:
给一个由
思路:
这题看题解还有点迷,其实也不是很难,就是要自己动手码,代码多改改,多思考下应该都能做出来。
自己随便写几个排列模拟下,不难发现,一次平移其实就是
特殊考虑一下最后一个数,这个数的
接着就是特殊考虑
最后还是
代码:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cstdlib>using namespace std;//#define abs(x) ((x) < 0 ? -(x) : (x))#define MS(x, y) memset(x, y, sizeof(x))typedef long long LL;const int MAXN = 1e6 + 5;int n;int p[MAXN], ones[MAXN << 1];int main() { while (~scanf("%d", &n)) { LL sum = 0, mn; int mn_idx = 0, pos = 0, neg = 0; MS(ones, 0); for (int i = 1; i <= n; ++i) { scanf("%d", p + i); sum += abs(p[i] - i); if (p[i] > i) ++pos; else ++neg; if (p[i] >= i) ++ones[p[i] - i]; } mn = sum; for (int i = 1; i <= n; ++i) { sum = sum - pos + neg - 1; sum = sum - abs(p[n - i + 1] - n) + p[n - i + 1] - 1; if (p[n - i + 1] != 1) { ++pos; --neg; } pos -= ones[i]; neg += ones[i]; ++ones[p[n - i + 1] - 1 + i]; if (sum < mn) { mn = sum; mn_idx = i; } } printf("%I64d %d\n", mn, mn_idx); }}
阅读全文
0 0
- Codeforces Round 421 Div.2 D. Mister B and PR Shifts 思维 乱搞
- Codeforces Round #421 (Div. 1):B. Mister B and PR Shifts 思维,乱搞
- Codeforces Round #421 (Div. 2) D. Mister B and PR Shifts
- Codeforces Round #421 (Div. 2) D. Mister B and PR Shifts
- #421 Div.2 D. Mister B and PR Shifts
- Codeforces Round #421 (Div. 1):B. Mister B and PR Shifts(瞎搞)
- CodeForces 820D Mister B and PR Shifts(思维题)
- CodeForces-820D Mister B and PR Shifts
- Codeforces Round #421 Mister B and PR Shifts(暴力瞎搞)
- Codeforces 819 B. Mister B and PR Shifts
- Codeforces 819B. Mister B and PR Shifts
- Codeforces Round #397(Div. 1 + Div. 2 combined)D. Artsem and Saunders【思维+乱搞】
- CF 820D Mister B and PR Shifts 差分(区间+k*(x-L)+b)
- Codeforces Round #421 (Div. 2) B. Mister B and Angle in Polygon
- Codeforces Round #421 (Div. 2) | B. Mister B and Angle in Polygon
- Codeforces Round #421 (Div. 2) A. Mister B and Book Reading
- Codeforces Round #421 (Div. 2) C. Mister B and Boring Game
- Codeforces Round #421 (Div. 2) | A. Mister B and Book Reading
- ionic2-部署测试
- 为什么我们会如此在乎别人的看法?
- ionic2-常用组件
- 配置Win10解决VMware Intel VT-x虚拟化问题
- 分享自己去年毕业,Java实习找工作的一些经验!
- Codeforces Round 421 Div.2 D. Mister B and PR Shifts 思维 乱搞
- ionic2- 导航页面
- ubuntu16.04 python3.5 Opencv3.2安装
- Java学习笔记-《Java程序员面试宝典》-第5章Java Web-5.2J2EE与EJB(5.2.5-5.2.10)
- EventBus的使用与原理
- LeetCode | 49. Group Anagrams
- 实现border内边距与图片半透明
- ecshop数据字典
- Linux下 XordDos(BillGates)木马查杀记录