Fighting strength vs Equipment

本文介绍了一种用于分析玩家装备价值与战斗实力间不匹配情况的算法,通过计算具有较低装备但战斗力更强的玩家数量来评估游戏平衡性。提供了一个C++实现示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

If you play games, you will know the importance of your equipment. However, your equipment is not the only thing to determine your success. Therefore, there are a lot of people winning without precious equipment because of their high fighting strength. Now, you are given a list of people's fighting strength(a1, a2, a3, ……, an). And the list is sorted according to their equipment value from low to high. Your target is to find how many such pairs(i, j) exists  where ai > aj which means people i with lower equipment but higher fighting strength than people j.

Input

The first line is just an integer n (1 < n < 1000000).

The second line are n integers a1, a2, a3……an(|ai| < 2^31)

Output

You just need to output the number of pairs described above .

Sample Input

53 2 1 4 5

Sample Output

3
#include <iostream>
using namespace std;
 
long long ans;
int b[1000100];
 
void Sort(int a[], int first, int last)
{
    if (first < last)
    {
        int mid = (first + last) / 2;
        Sort(a,first, mid);
        Sort(a,mid + 1, last);
        //merge(a, first, mid, last);
        int i = first, j = mid + 1, k = 0;
        while (i <= mid&&j <= last) {
            if (a[i] <= a[j])
                b[++k] = a[i++];
            else {
                ans += mid - i + 1;
                b[++k] = a[j++];
            }
        }
        while (i <= mid) b[++k] = a[i++];
        while (j <= last) b[++k] = a[j++];
        for (i = first; i <= last; i++) a[i] = b[i - first + 1];
    }
    return;
}
 
int main()
{
    int n;
    int a[1000100];
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    ans = 0;
    Sort(a,1, n);
    cout << ans << endl;
    return 0;
}
/**************************************************************
    Problem: 1129
    User: 141220110
    Language: C++
    Result: Accepted
    Time:760 ms
    Memory:9024 kb
****************************************************************/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值