zoukankan      html  css  js  c++  java
  • H-Index

    package cn.edu.xidian.sselab.hashtable;

    /**
     *
     * @author zhiyong wang
     * title: H-Index
     * content:
     *  Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.
     *  According to the definition of h-index on Wikipedia: "A scientist has index h if h of his/her N papers have at least h citations each, and the other N − h papers have no more than h citations each."
     *
     *For example, given citations = [3, 0, 6, 1, 5], which means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively. Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, his h-index is 3.
     *
     *Note: If there are several possible values for h, the maximum one is taken as the h-index.
     *
     */
    public class HIndex {

        //这道题,自己理解错了题意,正确的理解方式是:论文被引用次数大于或者等于h次,这样的论文数量也要大于或者等于h,此时的h才是H
        //注:h的取值返回是[0,论文的总篇数]
        //首先是建立一个数组,用于将论文的引用次数从小到大进行排序,当然引用次数大于总论文个数的都放在数组的最后一位
        //然后从数组最后一个开始,计算论文的个数是否大于或者等于论文引用的次数
        public int hIndex(int[] citations){
            int length = citations.length;
            int result = 0;
            if(length == 0) return 0;
            int[] index = new int[length+1];
            for(int i=0;i<length;i++){
                if(citations[i]>length){
                    index[length]++;
                }else{
                    index[citations[i]]++;
                }
            }
            for(int i=length;i>=0;i--){
                if(result >= i) return i;
                result +=index[i];
            }
            return 0;
        }
    }

  • 相关阅读:
    使用CustomValidate自定义验证控件
    C#中金额的大小写转换
    Andriod出错之Unable to build: the file dx.jar was not loaded from the SDK folder!
    VC 编写的打字练习
    机房工作笔记Ping只有单向通
    web服务协同学习笔记(1)
    Dll 学习3 将MDI子窗口封装在DLL中
    机房工作学习文件共享
    Andriod出错之Failed to find an AVD compatible with target 'Android 2.2'
    Andriod出错之wrapper was not properly loaded first
  • 原文地址:https://www.cnblogs.com/wzyxidian/p/5171247.html
Copyright © 2011-2022 走看看