CROC 2016 - Elimination Round (Rated Unofficial Edition) B. Mischievous Mess Makers 贪心
B. Mischievous Mess Makers
题目连接:
http://www.codeforces.com/contest/655/problem/B
Description
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 through n, 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.
Input
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
Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than k swaps.
Sample Input
5 2
Sample Output
10
Hint
题意
给你1到n的序列,然后你可以最多交换k次
让你使得逆序数最多,问你答案是多少
题解:
贪心,第一个数和最后一个数交换,第二个数和倒数第二个数交换,然后这样就好了
每次对答案的贡献是2*(n-i-i)+1
这个画画图就知道了。
代码
#include<bits/stdc++.h>
using namespace std;
long long ans,n,k;
int main()
{
cin>>n>>k;
for(int i=1;i+i<=n&&i<=k;i++)
ans+=2*(n-i-i)+1;
cout<<ans<<endl;
}
CROC 2016 - Elimination Round (Rated Unofficial Edition) B. Mischievous Mess Makers 贪心的更多相关文章
- CROC 2016 - Elimination Round (Rated Unofficial Edition) D. Robot Rapping Results Report 二分+拓扑排序
D. Robot Rapping Results Report 题目连接: http://www.codeforces.com/contest/655/problem/D Description Wh ...
- CROC 2016 - Elimination Round (Rated Unofficial Edition) D. Robot Rapping Results Report 拓扑排序+二分
题目链接: http://www.codeforces.com/contest/655/problem/D 题意: 题目是要求前k个场次就能确定唯一的拓扑序,求满足条件的最小k. 题解: 二分k的取值 ...
- CROC 2016 - Elimination Round (Rated Unofficial Edition) F - Cowslip Collections 数论 + 容斥
F - Cowslip Collections http://codeforces.com/blog/entry/43868 这个题解讲的很好... #include<bits/stdc++.h ...
- CROC 2016 - Elimination Round (Rated Unofficial Edition) E - Intellectual Inquiry dp
E - Intellectual Inquiry 思路:我自己YY了一个算本质不同子序列的方法, 发现和网上都不一样. 我们从每个点出发向其后面第一个a, b, c, d ...连一条边,那么总的不同 ...
- CROC 2016 - Elimination Round (Rated Unofficial Edition) E. Intellectual Inquiry 贪心 构造 dp
E. Intellectual Inquiry 题目连接: http://www.codeforces.com/contest/655/problem/E Description After gett ...
- CROC 2016 - Elimination Round (Rated Unofficial Edition) C. Enduring Exodus 二分
C. Enduring Exodus 题目连接: http://www.codeforces.com/contest/655/problem/C Description In an attempt t ...
- CROC 2016 - Elimination Round (Rated Unofficial Edition) A. Amity Assessment 水题
A. Amity Assessment 题目连接: http://www.codeforces.com/contest/655/problem/A Description Bessie the cow ...
- CF #CROC 2016 - Elimination Round D. Robot Rapping Results Report 二分+拓扑排序
题目链接:http://codeforces.com/contest/655/problem/D 大意是给若干对偏序,问最少需要前多少对关系,可以确定所有的大小关系. 解法是二分答案,利用拓扑排序看是 ...
- 8VC Venture Cup 2016 - Elimination Round D. Jerry's Protest 暴力
D. Jerry's Protest 题目连接: http://www.codeforces.com/contest/626/problem/D Description Andrew and Jerr ...
随机推荐
- spring-boot-资源处理
WebMvcConfigurerAdapter 使用 1.实现 HandlerInterceptorAdapter 2.添加拦截器 重写WebMvcConfigurerAdapter中的addInte ...
- 2017百越杯反序列化writeup
去年的了,之前也有研究过.只是因为感觉PHP反序列化挺好玩的所以就再研究了一遍.总之感觉反序列化漏洞挺好玩的. 题目代码: <?php class home{ private $method; ...
- 24 - 面向对象基础-多继承-super-mro-Mixin
目录 1 类的继承 2 不同版本的类 3 基本概念 4 特殊属性和方法 5 继承中的访问控制 6 方法的重写(override) 6.1 super 6.2 继承中的初始化 7 多继承 7.1 多继承 ...
- 一款线程安全、基本功能齐全的STL
MiniSTL 目前正在完成一个STL,主要想通过该项目锻炼C++编程.模板编程.熟悉STL.锻炼数据结构和算法能力. 项目的目标是实现STL的几大构件+线程安全.项目过程中主要参考SGI STL源码 ...
- ProxySQL(MGR)部署故障:'sys.gr_member_routing_candidate_status' doesn't exist
ProxySQL(MGR) 故障排查: 故障现象:runtime_mysql_servers节点状态offline_hostgroup(本案例为15) 日志关键信息: [WARNING] Group ...
- Jmeter命令行选项
示例:jmeter.bat -n -j %tmp%\%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%%time:~ ...
- 关于ORA-04091异常的出现原因,以及解决方案
问题分析 在Oracle中执行DML语句的时候是需要显示进行提交操作的.当我们进行插入的时候,会触发触发器执行对触发器作用表和扩展表的种种操作,但是这个时 候触发器和插入语句是在同一个事务管理中的,因 ...
- 利用json模块解析dict报错找不到attribute 'dumps'[python2.7]
[背景] 环境: RHEL 7.3 版本: python2.7 [错误情况] 写了一个简单的python脚本 将dict转换为json 脚本如下: #!/usr/bin/python #-*- cod ...
- procedure of object 对象的函数指针
应用:http://www.cnblogs.com/del88/p/6361117.html 有 class of object ----- 类的类型 那么自然有 方法的类型,方法的类型 分为两种: ...
- Hadoop2.5.2 安装部署
0x00 平台环境 OS: CentOS-6.5-x86_64 JDK: jdk-8u111-linux-x64 Hadoop: hadoop-2.5.2 0x01 操作系统基本设置 1.1 网络配置 ...