题意:给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的更多相关文章

  1. codeforces 352D - Jeff and Furik【期望dp】

    首先恋人操作过一轮之后逆序对不会变多,所以设f[i]为把i个逆序对消掉的期望次数,f[i]=0.5f[i-2]+0.5f[i]+2,化简然后递推即可 #include<iostream> ...

  2. Codeforces 351B Jeff and Furik:概率 + 逆序对【结论题 or dp】

    题目链接:http://codeforces.com/problemset/problem/351/B 题意: 给你一个1到n的排列a[i]. Jeff和Furik轮流操作,Jeff先手. Jeff每 ...

  3. 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 ...

  4. Codeforces 351B Jeff and Furik

    http://codeforces.com/problemset/problem/351/B 题意:两个人轮流游戏,先手交换相邻两个数,后手先抛硬币,正面就左大右小换,反面就右大左小换,随机找到一对数 ...

  5. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik

    http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...

  6. 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 ...

  7. codeforces B. Jeff and Periods 解题报告

    题目链接:http://codeforces.com/problemset/problem/352/B 题目意思:给出一个长度为n的序列   a1, a2, ..., an(序号i,1 <= i ...

  8. codeforces A. Jeff and Digits 解题报告

    题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...

  9. CodeForces 352C. Jeff and Rounding(贪心)

    C. Jeff and Rounding time limit per test:  1 second memory limit per test: 256 megabytes input: stan ...

随机推荐

  1. 【filter】springmvc web.xml

    1.filter用于拦截用户请求,在服务器作出响应前,可以在拦截后修改request和response,这样实现很多开发者想得到的功能. 2.filter实现 ×编写一个继承Filter接口的类 ×在 ...

  2. 一步步学习ASP.NET MVC3 (1)——基础知识

    请注明转载地址:http://www.cnblogs.com/arhat 首先在这里我想声明一下,这个ASP.NET MVC3系列是我在授课过程中的一些经验,有什么不对的地方,请大家指出,我们共同的学 ...

  3. Spring核心框架 - AOP的起源及介绍

    一.AOP技术起源 AOP技术的诞生并不算晚,早在1990年开始,来自Xerox Palo Alto Research Lab(即PARC)的研究人员就对面向对象思想的局限性进行了分析.他们研究出了一 ...

  4. C# and JSON

    JQuery Parse JSON var obj = $.parseJSON(data); C# creates JSON string: public static class JSONHelpe ...

  5. ubuntu下的文本查看相关命令

    文本查看 1.cat命令(查看文本内容) 使用时三种常用模式 (1)cat 文本名 直接查看文本内容 (2)cat 文本名 -n 直接查看文本内容,但为文本中所有行编号 (3)cat 文本名 -b 直 ...

  6. Provider Communication with Apple Push Notification Service

    This chapter describes the interfaces that providers use for communication with Apple Push Notificat ...

  7. css3 旋转出现动画

    @-moz-keyframes daf{ 0% { -moz-transform: rotate(-360deg) scale(0.2); -webkit-transform: rotate(-360 ...

  8. 一些常用的jQuery插件

    1. X-editable 这个插件能够让你在页面上创建可编辑的元素.它能够使用任何引擎(bootstrap.jquery-ui.jquery),并且包含弹出式和内联模式. 2. Garlic.js ...

  9. POJ 1236 Network of Schools[连通分量]

    题目链接:http://poj.org/problem?id=1236题目大意:给出N台电脑,电脑间单向连通传送文件问题1.网络中最少放几个文件保证所有电脑都能接受到文件问题2.最少向网络中加几条线保 ...

  10. codeforces 388C Fox and Card Game

    刚刚看到这个题感觉是博弈题: 不过有感觉不像,应该是个贪心: 于是就想贪心策略: 举了一个例子: 3 3 1 2 3 4 3 4 1 2 5 4 1 2 5 8 如果他们两个每次都拿对自己最有利的那个 ...