cf 204 div2 D. Jeff and Furik 逆序对

简介:

     又一次看错题意……题目是两个人,一个人自己主观选择,一个人抛硬币,因为算期望,所以抛硬币那人可以无视掉,求出逆序对个数m,m为奇答案是2m-1,否则2m

    太囧

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
using namespace std;
int org[100000];
int c[100000];
int ans=0;
void out(int *a,int n)
{
   for(int i=0;i<n;i++)
      printf("%d ",a[i]);
   puts("");
}
int meg(int l,int mid,int r)
{
    int i=l,j=mid+1,k=0;
    while(i<=mid)
    {
       while(j<=r&&org[i]>org[j])
          c[k++]=org[j++];
       ans+=j-mid-1;
       c[k++]=org[i++];
    }
    while(j<=r)c[k++]=org[j++];
    k=0;
    while(l<=r)org[l++]=c[k++];
}
void count(int l,int r)
{
    if(l<r)
    {
       int mid=(l+r)>>1;
       count(l,mid);
       count(mid+1,r);
       meg(l,mid,r);
    }
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
       ans=0;
        int i;
        for(i=0;i<n;i++)
           scanf("%d",&org[i]);
        count(0,n-1);
        double t;
        if(ans%2==0)ans*=2;
        else ans=ans*2-1;
        printf("%.6f\n",(double)(ans));
    }
}


目录
相关文章
|
2月前
|
Java
线程池详解与异步任务编排使用案例-xian-cheng-chi-xiang-jie-yu-yi-bu-ren-wu-bian-pai-shi-yong-an-li
线程池详解与异步任务编排使用案例-xian-cheng-chi-xiang-jie-yu-yi-bu-ren-wu-bian-pai-shi-yong-an-li
49 0
|
7月前
|
Serverless
华为机试HJ30:字符串合并处理
华为机试HJ30:字符串合并处理
|
7月前
华为机试HJ96:表示数字
华为机试HJ96:表示数字
|
8月前
|
人工智能 算法
Codeforces #737Div2A. A. Ezzat and Two Subsequences(模拟)
Codeforces #737Div2A. A. Ezzat and Two Subsequences(模拟)
24 0
|
8月前
|
机器学习/深度学习 人工智能 BI
The Great Hero(Codeforces Round #700 (Div. 2))模拟+贪心思想和排序
The Great Hero(Codeforces Round #700 (Div. 2))模拟+贪心思想和排序
35 0
|
12月前
【CodeForces】夜深人静写cf
Problem - B - Codeforces
42 0
|
12月前
CodeForces Feb/05/2023 DIV2 A1
CodeForces Feb/05/2023 DIV2 A1
52 0
CF817C.Really Big Numbers(二分 思维)
CF817C.Really Big Numbers(二分 思维)
50 0