H.Little Sub and Counting

Description

Little Sub likes Math. Now he has a simple counting problem for you.
Given an positive integer sequence A, for each Ai, Please calculate how many elements Aj in the sequence satisfied Ai^Aj > Aj^Ai.

Input

The first line contains one positive integer n(1 ≤ n ≤ 100000).
The following line contains n positive integers Ai(1 ≤ Ai ≤ 2^31 − 1).

Output

Please output n integer in one line and separate them by a single space. The ith integer indicates the answer concerning Ai.

Author
CHEN, Jingbang

题解:x^y>y^x -->取ln --> ylnx>xlny-->x/lnx<y/lny,以此为依据排序统计个数即可.
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
const int N=1e5+5;
using namespace std;
typedef long long ll;
double a[N];
double b[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lf",&a[i]),a[i]=1.0*a[i]/log(a[i]),b[i]=a[i];
    sort(b+1,b+1+n);
    for(int i=1;i<=n-1;i++){
        printf("%d ",n-(upper_bound(b+1,b+1+n,a[i])-b)+1);
    }
    printf("%d ",n-(upper_bound(b+1,b+1+n,a[n])-b)+1);
    //cout << "Hello world!" << endl;
    return 0;
}

转载于:https://www.cnblogs.com/-yjun/p/10549916.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值