zoukankan      html  css  js  c++  java
  • 牛客网之网易面试题

    输入描述:
    每个输入包含一个测试用例。
    每个测试用例的第一行包含两个正整数,分别表示工作的数量N(N<=100000)和小伙伴的数量M(M<=100000)。
    接下来的N行每行包含两个正整数,分别表示该项工作的难度Di(Di<=1000000000)和报酬Pi(Pi<=1000000000)。
    接下来的一行包含M个正整数,分别表示M个小伙伴的能力值Ai(Ai<=1000000000)。
    保证不存在两项工作的报酬相同。
    输出描述:
    对于每个小伙伴,在单独的一行输出一个正整数表示他能得到的最高报酬。一个工作可以被多个人选择。


    输入例子1:
    3 3 
    1 100 
    10 1000 
    1000000000 1001 
    9 10 1000000000


    C# 代码

    public void GetMn(int n,int m) {
    
                //输入测试实列N和M
                //N为工作的数量,M为小伙伴的数量
                Dictionary<int, int> map = new Dictionary<int, int>();
                int t1 = 0, t2 = 0;
                int[] a = new int[n];  //n的值
                int[] b = new int[m];  //存储m的值
                int[] shu = new int[n];  //存储金额最大
                //N行每行包含两个正整数,分别表示该项工作的难度Di(Di<=1000000000)和报酬Pi(Pi<=1000000000)。
                for (int i = 0; i < n; i++) {
                   
                    t1 = Convert.ToInt32(Console.ReadLine());  //Di
                    t2 = Convert.ToInt32(Console.ReadLine());   //Pi
                    a[i] = t1;  //Di
                    map.Add(t1, t2);  //对应难度和工资
    
                }
                //接下来的一行包含M个正整数,分别表示M个小伙伴的能力值Ai(Ai<=1000000000)。
                for (int j = 0; j < m; j++) {
                    t1 = Convert.ToInt32(Console.ReadLine()); //M个整数
                    //a[n + j] = t1;
                    b[j] = t1;  //存储m
                    if (!map.ContainsKey(t1)) 
                        map.Add(t1, 0);
                   
    
    
                }
                int max = 0;
                for (int i = 0; i <n; i++) {
                    max = Math.Max(max, map[a[i]]);
                    shu[i] = max;
    
                }
    
                for (int i = 0; i < shu.Length; i++) {
    
                    Console.WriteLine(shu[i]);
                }
    
    
    
    
    
            }
  • 相关阅读:
    Spring Boot----处理异常
    Spring Boot----SpringBoot中SpringMVC配置原理
    git----常见问题
    源码分析----Mybatis
    spring----一些xml配置
    Spring MVC----spring MVC 异常处理
    java----小游戏
    java----垃圾回收机制
    java----常见jar包
    anconda安装
  • 原文地址:https://www.cnblogs.com/mengluo/p/8886533.html
Copyright © 2011-2022 走看看