【CROC 2016 - Elimination RoundB】【贪心】Mischievous Mess Makers 全排列1到n交换k次最多逆序数
来源:互联网 发布:哈达利雾化器做丝数据 编辑:程序博客网 时间:2024/05/08 19:22
It is a balmy spring afternoon, and Farmer John's n cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 throughn, are arranged so that the i-th cow occupies the i-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his k minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute.
Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the k minutes that they have. We denote as pi the label of the cow in the i-th stall. The messiness of an arrangement of cows is defined as the number of pairs (i, j) such that i < j and pi > pj.
The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100 000) — the number of cows and the length of Farmer John's nap, respectively.
Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than k swaps.
5 2
10
1 10
0
In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10.
In the second sample, there is only one cow, so the maximum possible messiness is 0.
#include<stdio.h>#include<iostream>#include<string.h>#include<string>#include<ctype.h>#include<math.h>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }#define MS(x,y) memset(x,y,sizeof(x))#define MC(x,y) memcpy(x,y,sizeof(x))#define MP(x,y) make_pair(x,y)#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }const int N = 0, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;int n, k;int main(){while (~scanf("%d%d", &n,&k)){gmin(k, n / 2);LL ans = 0;for (int i = 1; i <= k; ++i){LL mid = (n - 2 * i);ans += 2 * mid + 1;}printf("%d\n", ans);}return 0;}/*【trick&&吐槽】很多sb都爆了int,>_<~~【题意】给你一个长度为n(1e5)的全排列,数字从1到n。我们最多可以交换k(1e5)次,任意交换位置。问你可以交换得到的最大逆序对数【类型】贪心【分析】每次交换最前最后即可*/
- 【CROC 2016 - Elimination RoundB】【贪心】Mischievous Mess Makers 全排列1到n交换k次最多逆序数
- (CROC 2016 - Elimination Round (Rated Unofficial Edition))B. Mischievous Mess Makers(贪心)
- Codeforces 645B Mischievous Mess Makers【逆序数】
- 题解:Mischievous Mess Makers
- Codeforces 645B Mischievous Mess Makers 【逆序对】
- CodeForces 645B Mischievous Mess Makers
- Code Forces 645B Mischievous Mess Makers
- CodeForces 645 B.Mischievous Mess Makers(水~)
- ACM-有一个数n(0<n<10),写出1到n的全排列
- 第n次全排列
- 全排列和逆序数
- 全排列及其逆序数
- Codeforces CROC 2016 - Elimination Round
- CROC 2016 - Elimination Round B 树状数组处理逆序对个数
- 1到n的全排列
- 1到n的全排列实现
- 输出 1 到 n 的全排列
- (CROC 2016 - Elimination Round (Rated Unofficial Edition))A. Amity Assessment(贪心)
- [J2EE]java集合
- SQL-按照最新时间分组
- Python小爬虫小总
- 【CROC 2016 - Elimination RoundA】【水题 循环暴力】Amity Assessment 2x2华容道
- Jvm参数配置
- 【CROC 2016 - Elimination RoundB】【贪心】Mischievous Mess Makers 全排列1到n交换k次最多逆序数
- HDOJ 3785 寻找大富翁
- Python快速入门(1)
- spring mvc mvc:interceptors 零配置(带 urlpattern)
- linux + nginx + ngx_cache_purge 缓存清理
- HDFS源码分析心跳汇报之数据块汇报
- 【CROC 2016 - Elimination RoundC】【二分】Enduring Exodus 最小的人看守与羊距离
- 33.多线程之GCD
- 射线