zoukankan      html  css  js  c++  java
  • 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

    题解:xy>yx -->取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;
    }
    
    
  • 相关阅读:
    鞍点计算
    hdu-2546 饭卡 01背包
    判断2的个数
    1959: 图案打印
    1913: 成绩评估
    1908: 蟠桃记
    采药问题 01背包
    JAVA反射机制_获取Class中的构造函数
    JAVA反射机制_获取字节码文件对象
    tcp饭卡上两地分居克里斯丁
  • 原文地址:https://www.cnblogs.com/-yjun/p/10549916.html
Copyright © 2011-2022 走看看