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 ...
随机推荐
- Python按照索引访问list
由于list是一个有序集合,所以,我们可以用一个list按分数从高到低表示出班里的3个同学: >>> L = ['Adam', 'Lisa', 'Bart'] 那我们如何从list中 ...
- 使用KVC
KVC是Key Value Coding的简称,意思是键值编码,号称Cocoa的大招.它是一种可以直接通过字符串key(对象在名称)来访问或修改对象属性的机制. 使用 1.利用KVC可以随意修改一个对 ...
- hadoop-streaming 配置之---参数分割
map: -D stream.map.output.field.separator=. 定义mapoutput字段的分隔符为. 用户可以自定义分隔符(除了默认的tab) -D stream.num.m ...
- linux(centos)如何查看文件夹大小
参考http://zhidao.baidu.com/link?url=OrfDgdHvyA1pSDAy6ql-IgPBWtvcS5AR9bc543zTr1hLIDfCd42nYtNBplAl2pHvM ...
- Html中如何让超链接a、图片img居中
一.问题来源 修改博客页面时,突然想到 二.解决办法 2.1原来办法 在img和a中加入align="center",发现不行 2.2百度答案 <div align=&quo ...
- [CC150] 八皇后问题
Write an algorithm to print all ways of arranging eight queens on an 8*8 chess board so that none of ...
- Weex详解:灵活的移动端高性能动态化方案
原文地址:http://www.infoq.com/cn/articles/introducing-weex 在2016年4月份的QCon上,阿里巴巴资深总监,淘宝移动平台及新业务事业部.阿里百川负责 ...
- HttpOnly
Contents 1 Overview 1.1 Who developed HttpOnly? When? 1.2 What is HttpOnly? 1.3 Mitigating the Most ...
- jquery mobile script
http://blog.csdn.net/lyatzhongkong/article/details/6969913 http://book.51cto.com/art/201209/355980.h ...
- 【NOIP TG 解方程】
存代码: #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> ...