笔试时间:2023年08月26日 秋招  第一题  题目:小美种果树  小美在手机上种果树,只要成熟了就可以领到免费的水果了。小美每天可以给果树浇水,果树的成长值加x。同时也可以给果树施肥,两次施肥至少需要间隔 2 天,果树的成长值加 y。果树成长值达到z就成熟了。小美想知道,最少需要多少天可以领到免费的水果。  输入描述  一行三个整数x,y,z,分别表示浇水的成长值,施肥的成长值,果树成熟的成长值。1<=x,y,z<=10^9  输出描述  一行一个整数,表示最少需要多少天可以领到免费的水果。  样例输入     1 2 10    样例输出     6    说明  第一天施肥浇水,成长值为 3。  第二天浇水,成长值为 3 + 1 = 4。  第三天浇水,成长值为 4 + 1 = 5。  第四天施肥浇水,成长值为 5 + 3 = 8。  第五天浇水,成长值为 8 + 1 = 9。  第六天浇水,成长值为 9 + 1 = 10。  果树成熟了,可以领到免费水果了!  参考题解  模拟  C++:  #include <iostream>using namespace std;int main() {    int x, y, z;    cin >> x >> y >> z;    int remainder = z % (3 * x + y);    if (remainder == 0) {        cout << (z / (3 * x + y)) * 3 << endl;    } else {        if (remainder < x + y) {            cout << (z / (3 * x + y)) * 3 + 1 << endl;        } else if (remainder < 2 * x + y) {            cout << (z / (3 * x + y)) * 3 + 2 << endl;        } else {            cout << (z / (3 * x + y)) * 3 + 3 << endl;        }    }    return 0;}  Java:  import java.util.Scanner;public class Main {    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int x = sc.nextInt();        int y = sc.nextInt();        int z = sc.nextInt();        int remainder = z % (3 * x + y);        if (remainder == 0) {            System.out.println((z / (3 * x + y)) * 3);        } else {            if (remainder < x + y) {                System.out.println((z / (3 * x + y)) * 3 + 1);            } else if (remainder < 2 * x + y) {                System.out.println((z / (3 * x + y)) * 3 + 2);            } else {                System.out.println((z / (3 * x + y)) * 3 + 3);            }        }    }}  Python:  x,y,z = map(int, input().split())yu = z % (3*x + y)if yu == 0:    print(z //(3*x + y) * 3)else:    if yu < x + y:        print(z //(3*x + y) * 3 + 1)    elif yu < 2*x + y:        print(z // (3 * x + y) * 3 + 2)    else:        print(z // (3 * x + y) * 3 + 3)  第二题  题目:小美结账  大家一起吃饭的时候,总是小美先付钱,然后大家再把钱转给小美。现在小美有n张账单,每张账单记录了有k个人一起吃饭,以及吃饭的消费c,现在小美需要计算每个人需要转给小美多少钱。由于大家都比较喜欢整数,所以大家每张账单会转给小美[c/k],[x]表示对x进行上取整。  输入描述  第一行输入两个整数n,m(1<=n,m<=10^5)表示账单数和除小美外的总人数(分别用1到m表示)。  接下来2*n行,每 2行表示一张账单。对于每张账单:  第一行输入两个整数n,m(1<=n,m<=10^5)表示一起吃饭的人数,花费。  第二行输入k-1个整数,表示除小美外有哪些人一起吃饭。  数据保证,k的总和不超过2*10^5 。  输出描述  输出m个整数,表示每个人要给小美转账的总金额。  样例输入     2 3   3 10   1 2   4 8   1 2 3    样例输出     6 6 2    说明  第一张账单:第1、2个人都会给小美转4元  第二张账单:第1、2、3个人都会给小美转2元  因此答案为4+2=6,4+2=6,2  参考题解  模拟  C++:  #include <iostream>#include <vector>#include <cmath>using namespace std;int main() {    int n, m;    cin >> n >> m;    vector<int> res(m + 1, 0);    for (int i = 0; i < n; i++) {        int k, c;        cin >> k >> c;        vector<int> people(k);        for (int j = 0; j < k; j++) {            cin >> people[j];        }        for (int p : people) {            res[p] += ceil((double)c / k);        }    }    for (int i = 1; i <= m; i++) {        cout << res[i] << " ";    }    return 0;}  Java:  import java.util.Scanner;public class Main {    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int n = sc.nextInt();        int m = sc.nextInt();        int[] res = new int[m + 1];        for (int i = 0; i < n; i++) {            int k = sc.nextInt();            int c = sc.nextInt();            int[] people = new int[k];            for (int j = 0; j < k; j++) {                people[j] = sc.nextInt();            }            for (int p : people) {                res[p] += Math.ceil((double) c / k);            }        }        for (int i = 1; i <= m; i++) {            System.out.print(res[i] + " ");        }    }}  Python:  import mathn,m = map(int, input().split())res = [0]*(m + 1)for _ in range(n):    k,c = map(int, input().split())    people = [int(c) for c in input().split()]    for p in people:        res[p] += math.ceil(c/k)for i in range(1, m+1):    print(res[i], end=" ")  第三题  题目:小美的游戏  小美有一个长度为n的数组,她最多可以进行k次操作,每次操作如下:  1、选择两个整数i,j(1<=i<j<=n)  2、选择两个整数x,y,使得xy=aiaj  3、将ai替换为x,将aj替换为y  她希望最多进行k次操作之后,最后数组中的元素的总和尽可能大。  输入描述  一行两个整数n,k,表示数组的长度和操作的次数。  一行n个整数
点赞 2
评论 0
全部评论

相关推荐

牛客316659795号:不是,证明hr初筛已经过了,要投给部门筛一遍
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务