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));
    }
}


目录
相关文章
|
8天前
|
算法
并查集,真好用,一次AC不是梦
并查集,真好用,一次AC不是梦
|
22天前
|
存储
六道入门树题目带你走入树结构的世界-liu-dao-ru-men-shu-ti-mu-dai-ni-zou-ru-shu-jie-gou-de-shi-jie
六道入门树题目带你走入树结构的世界-liu-dao-ru-men-shu-ti-mu-dai-ni-zou-ru-shu-jie-gou-de-shi-jie
5 0
|
4月前
BUUCTF john-in-the-middle 1
BUUCTF john-in-the-middle 1
26 0
|
11月前
|
C++
Learning C++ No.15【STL No.5】list的实现
Learning C++ No.15【STL No.5】list的实现
|
11月前
【CodeForces】夜深人静写cf
Problem - B - Codeforces
42 0
|
11月前
CodeForces Feb/05/2023 DIV2 A1
CodeForces Feb/05/2023 DIV2 A1
52 0
每日一题---27. 移除元素[力扣][Go]
每日一题---27. 移除元素[力扣][Go]
每日一题---27. 移除元素[力扣][Go]
|
算法 Go
每日一题---31. 下一个排列[力扣][Go]
每日一题---31. 下一个排列[力扣][Go]
每日一题---31. 下一个排列[力扣][Go]
每日一题---1446. 连续字符[力扣][Go]
每日一题---1446. 连续字符[力扣][Go]
每日一题---1446. 连续字符[力扣][Go]
CF817C.Really Big Numbers(二分 思维)
CF817C.Really Big Numbers(二分 思维)
49 0