ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

牛客测评题

2021-02-02 23:01:44  阅读:186  来源: 互联网

标签:RP String 测评 int ts kn 牛客 isEmpty


/***
 * 链接:https://ac.nowcoder.com/acm/evaluate/5697/A
 * 来源:牛客网
 *
 * 在统计学中,移动平均值是一种很有用的分析工具,它可以较好地体现数据的发展趋势。它的计算方法如下:若依次得到n个数据
 * (x_1,x_2,...,x_n)(x1,x2,...,xn时,按顺序取k个数所做的全部算术平均值。
 * 现在给你n个实数及一个整数k,请你编程求出所有移动平均值中最大的和最小的之间的差值。
 * 输入说明:
 * 第一行输入为n和k,n为实数的个数,k的含义如题
 * 第二行输入n个实数x_{1},x_{2},…,x_{n}x1,x2,…,x n
 * ​
 *
 */
public class RumenA {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String kn = "";
        String arr = "";
        while (in.hasNextLine()){
            if(kn.isEmpty()){
                kn = in.nextLine();
            }else{
                arr = in.nextLine();
            }
            if(!kn.isEmpty()&&!arr.isEmpty()){
                System.out.println(test(kn,arr));
                kn = "";
                arr = "";
            }
        }
    }

    public static  String test(String kn,String arr){
        String[] temp = kn.split(" ");
        int n = Integer.parseInt(temp[0]);
        int k = Integer.parseInt(temp[1]);
        String[] arrs =(arr.trim()).split(" ");
        int[] a = new int[arrs.length];
        for (int i = 0; i <a.length ; i++) {
            a[i] = Integer.parseInt(arrs[i]);
        }

        double min = getv(k,a,0);
        double max =min;
        for (int i = 1; i <a.length-k+1 ; i++) {
            double v = getv(k,a,i);
            if(v>max){
                max = v;
            }
            if(v<min){
                min= v;
            }
        }
        return (max-min)+"";
    }

    private static double getv(int k,int[] a,int start){
        int count = 0 ;
        int temp = k;
        while (k>0){
            count +=a[start];
            start++;
            k--;
        }
        return count/((double)temp);
    }
}

/**
 * 链接:https://ac.nowcoder.com/acm/evaluate/5697/C
 * 来源:牛客网
 *
 * 牛能参加了一次牛客网组织的比赛。比赛一共三题,75分钟。比赛的规则是这样的,假如他花了t分钟解决第一题,他将在这道题得p1−2t分;花了t分钟解决第二题,
 * 得到p2−4t分;花t分钟解决第三题,得到p3−8t分,其中p1,p2,p3p分别是三道题的初始分值。
 * 在比赛中,RP总是很重要的。牛能知道,假如自己花x点RP在一道题上,这道题的解题时间能减少x分钟(但每题最终花费时间只能是正数)。
 * 现在牛能知道自己不花RP解每道题的时间,自己总的RP值和每道题的分数,他想知道最多自己能在比赛中获得多少分。
 * 第一行输入三个整数p1,p2,p3p 表示每题的初始分。
 * 第二行输入三个整数t1,t2,t3表示不用RP时每题所需时间。
 * 第三行输入一个整数RP,表示总RP值。
 *
 */
public class RumenC {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String ps = "";
        String ts = "";
        String rps = "";
        while (in.hasNextLine()){
            if(ps.isEmpty()){
                ps = in.nextLine();
            }else if(ts.isEmpty()){
                ts = in.nextLine();
            }else {
                rps = in.nextLine();
            }
            if(!ps.isEmpty()&&!ts.isEmpty()&&!rps.isEmpty()){
                System.out.println(test(ps,ts,rps));
                ps = "";
                ts = "";
                rps = "";
            }
        }
    }

    private static  String test(String ps,String ts,String rps){
        String[] tarr = ts.split(" ");
        int[] t =new int[tarr.length];
        int rp = Integer.parseInt(rps);
        for (int i = t.length -1; i>=0 ; i--) {
            t[i] = Integer.parseInt(tarr[i]);
            if(rp>t[i]-1){
                rp =rp - t[i]+1;
                t[i] = 1;
                continue;
            }
            if(rp<=t[i]-1){
                t[i] =t[i]-rp;
                rp =0;
                continue;
            }
        }
        int corde=0;
        String[] parr=ps.split( " ");
        int[] p =new int[parr.length];
        for (int i = 0; i <p.length ; i++) {
            p[i] = Integer.parseInt(parr[i]);
            if(i==0){
                corde +=p[i]-2*t[0];
            }
            if(i==1){
                corde +=p[i]-4*t[1];
            }
            if(i==2){
                corde +=p[i]-8*t[2];
            }
        }
        return corde+"";
    }
}

 

 

标签:RP,String,测评,int,ts,kn,牛客,isEmpty
来源: https://blog.csdn.net/gongweixin2018/article/details/113576166

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有