CSA Round #50 (Div. 2 only) Min Swaps(模拟)
传送门
题意
给出一个排列,定义\(value为\sum_{i=1}^{n-1}abs(f[i+1]-f[i])\)
\(swap(a[i],a[j])(i≠j)为一次交换\),询问最少的交换次数使得value最大
分析
如果f[i+1]>f[i],答案就+f[i+1]-f[i];
如果f[i+1]<f[i],答案就+f[i]-f[i+1];
那么我们可以找到一个pretty good solution
定义 L 为 f[i]<=n/2, R 为 f[i]>n/2,
得到L R L R L R L R
或 R L R L R L R L
可以发现2~n-1的R加了2次,L减了2次,1和n加或减1次,那么必定是
将n/2和n/2+1放在(1和n)或(n和1)的位置
If 2 is not first, bring it thereIf 3 is not the last, bring it thereSwap every pair of 0 and 1 that are not on their positions
CSA Round #50 (Div. 2 only) Min Swaps(模拟)的更多相关文章
- DP BestCoder Round #50 (div.2) 1003 The mook jong
题目传送门 /* DP:这题赤裸裸的dp,dp[i][1/0]表示第i块板放木桩和不放木桩的方案数.状态转移方程: dp[i][1] = dp[i-3][1] + dp[i-3][0] + 1; dp ...
- 简单几何(水)BestCoder Round #50 (div.2) 1002 Run
题目传送门 /* 好吧,我不是地球人,这题只要判断正方形就行了,正三角形和正五边形和正六边形都不可能(点是整数). 但是,如果不是整数,那么该怎么做呢?是否就此开启计算几何专题了呢 */ /***** ...
- Codeforces Round #368 (Div. 2) B. Bakery (模拟)
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...
- csa Round #66 (Div. 2 only)
csa66 Risk Rolls Time limit: 1000 msMemory limit: 256 MB Alena and Boris are playing Risk today. W ...
- Codeforces Round #243 (Div. 2)——Sereja and Swaps
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012476429/article/details/24665103 题目链接 题意: 给定一个整数 ...
- csa Round #73 (Div. 2 only)
Three Equal Time limit: 1000 msMemory limit: 256 MB You are given an array AA of NN integers betwe ...
- BestCoder Round #50 (div.1) 1003 The mook jong (HDU OJ 5366) 规律递推
题目:Click here 题意:bestcoder 上面有中文题目 分析:令f[i]为最后一个木人桩摆放在i位置的方案,令s[i]为f[i]的前缀和.很容易就能想到f[i]=s[i-3]+1,s[i ...
- BestCoder Round #50 (div.1) 1001 Distribution money (HDU OJ 5364)
题目:Click here 题意:bestcoder上面有中文题目 #include <iostream> #include <cstdio> #include <cst ...
- BestCoder Round #50 (div.1) 1002 Run (HDU OJ 5365) 暴力枚举+正多边形判定
题目:Click here 题意:给你n个点,有多少个正多边形(3,4,5,6). 分析:整点是不能构成正五边形和正三边形和正六边形的,所以只需暴力枚举四个点判断是否是正四边形即可. #include ...
随机推荐
- easyui datagrid client搜索、分页、排序
easyui datagrid的排序默认是server端排序.能够用sorter实现client排序[2].client分页可用filter实现[3].client搜索相同能够用filter实现. 不 ...
- Go与C语言的互操作 cgo
http://tonybai.com/2012/09/26/interoperability-between-go-and-c/ // foo.h int count; void foo(); //f ...
- 基于jquery 全选、反选、各行换色、单击行选中事件实现代码
<script language="javascript"> $(document).ready(function(){ //各行换色 $('table tr:odd' ...
- 当年用httpclient时踩过的那些坑
一.前言 httpclient是java开发中最常用的工具之一,通常大家会使用其中比较基础的api去调用远程.长期开发爬虫,会接触httpclient不常用的api,同时会遇到各式各样的坑,本文将总结 ...
- device not managed by NetworkManager
Bringing up interface eth0:Error:Connection activation failed:Device not managed by NetworkManager ...
- (转)OutOfMemory时抓取heap 快照
转自:https://testerhome.com/topics/579 首先说一下,在程序没有崩溃的时候如何抓取heap快照.这个大家应该都知道,在ddms中自带此功能. 见上图首先我们选中一个 ...
- python实现斐波那契查找
通过在网上找教程解释和看书,总结出一套比较简单易懂的代码实现. 斐波那契查找和二分查找一样,针对的是有序序列,在此前提下: # 先创建一个Fibonacci函数 fib = lambda n: n i ...
- Linux fork函数具体图解-同一时候分析一道腾讯笔试题
原创blog.转载请注明出处 头文件: #include<unistd.h> #include<sys/types.h> 函数原型: pid_t fork( void); (p ...
- VC FTP服务器程序分析(一)
想在QT上移植一个FTP服务器程序,先学习windows下的FTP服务器例子,然后随便动手写点东西. 在pudn上搜索 "FTP服务器端和客户端实现 VC“这几个关键字,就可以搜到下面要分析 ...
- monitor.sh java脚本学习
#! /bin/bash# unset any variable which system may be using# clear the screen while getopts ivh named ...