题意:给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. 异步委托 多线程实现摇奖器 winform版

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  2. swift-UILabel

    // Mark: 2. 创建label private func creatLabel(title: NSString)->UILabel{ /// 创建label let titleL = U ...

  3. mysql中实现行号,oracle中的rowid

    mysql中实现行号需要用到MYSQL的变量,因为MySql木有rownumber. MYSQL中变量定义可以用 set @var=0 或 set @var:=0 可以用=或:=都可以,但是如果变量用 ...

  4. const变量的存储区及修改权限

    转自const变量的存储区及修改权限 [cpp] view plaincopy const int a = 1; int *p = const_cast<int*>(&a); *p ...

  5. gcc和g++的区别

    参考What is the difference between g++ and gcc? 1.The actual compiler is "cc1" for C and &qu ...

  6. 【HDU 3038】 How Many Answers Are Wrong (带权并查集)

    How Many Answers Are Wrong Problem Description TT and FF are ... friends. Uh... very very good frien ...

  7. 使用NSURLSession实现断点续传

    在sb中创建按钮,并且连线到.m文件中

  8. easyui源码翻译1.32---ProgressBar(进度条)

    前言 使用$.fn.progressbar.defaults重写默认值对象.下载该插件翻译源码 进度条提供了一个反馈显示一个长时间运行的操作进展.可以更新的进展条,让用户知道当前正在执行操作. 源码 ...

  9. java中遍历List中的map问题

    List list = new ArrayList();Map map = null; while (rs.next()) { map = new HashMap(); map.put("f ...

  10. logstash gsub替换

    { "message" => "192.168.11.186,192.168.11.187\t48391,3306\tDec 7, 2016 13:26:25.13 ...