CodeForces 352D. Jeff and Furik
题意:给n个数,第一个人选取相邻两个递降的数交换顺序,第二个人一半的概率选取相邻两个递降的数交换顺序,一半的概率选取相邻两个递增的数交换顺序。两个人轮流操作,求整个数列变成递增数列所需交换次数的期望。
题解:首先显然要求逆序对数,记为cnt。想了很多计算概率加组合数等,没算出来= =
后来看了题解找规律,当cnt是奇数时,答案是cnt*2-1,当cnt是偶数时,答案是cnt*2
(自己算一下也能算出来,但是没有完全不知道怎么证明,解法就算了,但是以后知道这种题可以直接推公式了……)
代码:
#include <cstdio> int a[3005]; int main()
{
//freopen("in.txt", "r", stdin); int n;
scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", &a[i]); int cnt = 0; // 逆序对数
for (int i = 1; i < n; ++i)
for (int j = 0; j < i; ++j)
if (a[i] < a[j]) ++cnt; if (cnt & 1) printf("%d", cnt * 2 - 1);
else printf("%d", 2 * cnt); return 0;
}
CodeForces 352D. Jeff and Furik的更多相关文章
- codeforces 352D - Jeff and Furik【期望dp】
首先恋人操作过一轮之后逆序对不会变多,所以设f[i]为把i个逆序对消掉的期望次数,f[i]=0.5f[i-2]+0.5f[i]+2,化简然后递推即可 #include<iostream> ...
- Codeforces 351B Jeff and Furik:概率 + 逆序对【结论题 or dp】
题目链接:http://codeforces.com/problemset/problem/351/B 题意: 给你一个1到n的排列a[i]. Jeff和Furik轮流操作,Jeff先手. Jeff每 ...
- Codeforces 351B Jeff and Furik 概率 | DP
B. Jeff and Furik time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces 351B Jeff and Furik
http://codeforces.com/problemset/problem/351/B 题意:两个人轮流游戏,先手交换相邻两个数,后手先抛硬币,正面就左大右小换,反面就右大左小换,随机找到一对数 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik
http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...
- Codeforces Round #204 (Div. 2)->D. Jeff and Furik
D. Jeff and Furik time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- codeforces B. Jeff and Periods 解题报告
题目链接:http://codeforces.com/problemset/problem/352/B 题目意思:给出一个长度为n的序列 a1, a2, ..., an(序号i,1 <= i ...
- codeforces A. Jeff and Digits 解题报告
题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...
- CodeForces 352C. Jeff and Rounding(贪心)
C. Jeff and Rounding time limit per test: 1 second memory limit per test: 256 megabytes input: stan ...
随机推荐
- new 的用法
在C#中,new关键字有三种用法: 1.new 运算符,用于创建对象和调用构造函数. 2.new 修饰符,在用作修饰符时,new关键字可以显式隐藏从基类继承的成员. 3.new 约束 ,用于在泛型 ...
- C++编写操作系统(1):基于 EFI 的 Bootloader
很久以前就对操作系统很好奇,用了这么多年Windows,对他的运作机理也不是很清楚,所以一直想自己动手写一个,研究一下操作系统究竟是怎么实现的.后来在网上也找到过一些教程(比如:<自己动手写操作 ...
- white-space 属性设置如何处理元素内的空白
定义和用法white-space 属性设置如何处理元素内的空白. 这个属性声明建立布局过程中如何处理元素中的空白符.值 pre-wrap 和 pre-line 是 CSS 2.1 中新增的. 默认值: ...
- linux运维面试题
一.有文件file1 1.查询file1 里面空行的所在行号 grep -n "^#" file1 or awk ‗{if($0~/^$/)print NR}‘ file or g ...
- [转载]初学C#之list
C# List<T>用法 所属命名空间:System.Collections.Generic public class List<T> : IList<T>, IC ...
- APT攻防对抗
APT(高级持续性威胁)攻击是指近年来,专业甚至是有组织和国家背景支持的黑客,针对重要目标和系统发起的一种攻击手段,主要特征有 1)持续性:攻击者为了重要的目标长时间持续攻击直到攻破为止.攻击成功用上 ...
- Android版:验证手机号码的正则表达式
http://blog.csdn.net/dai_zhenliang/article/details/8186249 /** * 验证手机格式 */ public static boolean isM ...
- HDU 1400 (POJ 2411 ZOJ 1100)Mondriaan's Dream(DP + 状态压缩)
Mondriaan's Dream Problem Description Squares and rectangles fascinated the famous Dutch painter Pie ...
- 网络基本功(八):细说TCP滑动窗口
https://community.emc.com/message/842129#842129
- 如何忽略usb host 模式设备连接确认对话框
<li class="alt"><span><span>package android.hardware.usb; </span> ...