2021 Meituan School Recruitment (1)

Xiaomei's flower delivery route

Insert picture description here

Enter description

The first line of output contains a positive integer n, which is the total number of florists and customers. (1<=n<=30000)
There are n-1 rows next, and each row has three integers u, v, w, indicating that there is a road with a distance of w between u and v. (1<=w<=1000)

Output description

Input
5
1 2 3
1 3 1
1 4 2
2 5 1

Output
10 10

Ideas

Deep search is over

coding

#include <bits/stdc++.h>
using namespace std;
int main() {
    
    
    int n;
    scanf("%d", &n);
    unordered_map<int, vector<pair<int, int>>> mp;
    int total = 0;
    while (--n) {
    
    
        int sor, des, w;
        scanf("%d%d%d", &sor, &des, &w);
        mp[sor].push_back({
    
    des, w});
        total += w;
    }
    queue<pair<int, int>> q;
    q.push({
    
    1, 0});
    int maxLength = -1, sumLength = 0;
    while (!q.empty()) {
    
    
        pair<int, int> p = q.front();
        q.pop();
        int len = mp[p.first].size();
        if (!len) {
    
    
            maxLength = max(maxLength, p.second);
        } else {
    
    
            for (int i = 0; i < len; ++i) {
    
    
                pair<int, int> tmp = mp[p.first][i];
                q.push({
    
    tmp.first, p.second + tmp.second});
                sumLength += (p.second + tmp.second);
            }
        }      
    }
    total = total * 2 - maxLength;
    cout << sumLength << ' ' << total << endl;    
    return 0;
}

Xiaomei's scoring calculator

Meituan’s evaluation system for merchants is a 1-5 star evaluation system. After completing an order, users can rate merchants with 1/2/3/4/5 stars. On the client side, merchants’ ratings are not necessarily integers. Instead, one digit after the decimal point will be displayed. Obviously, this requires a calculator. Xiaomei has some merchant evaluation data and hopes to calculate the score displayed by the merchant on the client.
The calculation of this score is very simple, that is, to average the star ratings of all customers of the business, and then display one decimal place after the tail method. For example, if the average score is 3.55, it will display 3.5. For example, if a business has received 1-5 star reviews, the displayed score is (1+2+3+4+5)/5=3.0.

Enter description

The input contains 5 integers, which in turn indicate the number of reviews from 1 to 5 stars that the merchant has received, and the number of each type of review is not greater than 1000.

Output description

The output contains only one decimal place, which represents the rating displayed by the merchant on the client.

Instance

Input
2 2 1 1 2

Output
2.8

Ideas

Just expand the number ten times, then round down, and then reduce it ten times.

coding

#include<bits/stdc++.h>
using namespace std;
int ans[5];
double fun(double &num){
    
    
    double Num=num*10;
    double n;
    n=int(Num);
    return n/10;
}
int main(){
    
    
    int sum=0;
    float cos=0.0;
    double a;
    for(int i=1;i<=5;i++){
    
    
        scanf("%d",&ans[i]);
        cos+=ans[i];
        sum+=ans[i]*i;
    }
    a=sum/cos;
    //cout<<sum<<cos<<a;
    printf("%.1lf",fun(a));
    return 0;
}

Xiaomei's takeaway money saving plan

618 in 2020 is no longer just a shopping festival, it is also a Meituan takeaway festival. Xiaomei has prepared a variety of discount vouchers early on. In order to "save money" to the greatest extent, of course, I chose to use all these vouchers. Run out!
These vouchers have a threshold for use, that is, an order of how many yuan can be used. If you use a two-tuple <x,y> to represent a voucher, that is, you need to be at least x yuan to discount y yuan, then it should be noted that not all vouchers have x greater than or equal to y. Conscience Meituan There will also be some x<y vouchers. If x<y, for example, x=1, y=2, no payment is required for the purchase of 1 yuan of goods, and no refund will be given to the user.
If Xiaomei wants to use up these vouchers, how much can she buy for takeaway with the minimum guaranteed total payment amount?
Note:
1. Only one voucher can be used for an order.
2. At the same time, the total payment amount is the least, and the takeaway value purchased is the highest. For example, two takeaways with a discount of 1 yuan, one with an original price of 3 yuan and an original price of 4 yuan, choose four yuan.
3. Since there are many Meituan merchants, we can find at least one product to buy at any price.

Enter description

The first line of input contains only a positive integer n, which represents the number of vouchers owned by Xiaomei. (1<=n<=50000)
Next, there are n rows. Each row has two integers x and y, which means that a voucher can be used if the order amount is more than x yuan, and it can be discounted by y yuan. (1<=x<=10000,1<=y<=10000)

Output description

The output contains only two positive integers, separated by a space, respectively representing the value of the takeaway purchased by Xiaomei and her actual payment amount.

Instance

Enter
3
5 3
10 5
1 2

Output
17 7

Ideas

Store the data in the structure, and then discuss it by situation.

coding

#include<bits/stdc++.h>
using namespace std;
struct node{
    
    
    int x;   //满多少
    int y;   //优惠价格
    int z;   //付款钱
}money;
int ans[50005];
int main(){
    
    
    int n;
    int X=0,Y=0;
    cin>>n;
    while(n--){
    
    
        scanf("%d %d",&money.x,&money.y);
        if(money.x>money.y){
    
    
            X+=money.x;
            Y+=money.x-money.y;
        }
        else{
    
    
            X+=money.y;
            Y+=0;
        }
    }
    cout<<X<<' '<<Y;
    return 0;
}

Xiaomei's voucher is about to expire

The takeaway festival is about to pass, and Xiaomei still has a lot of vouchers not consumed. Meituan has launched a new event for users like Xiaomei, namely, the vouchers and fun activities. The system will shuffle the order of Xiaomei’s vouchers into a row. Xiaomei can perform any number of operations as follows:
If there are two adjacent vouchers with equal amounts, set their denominations to x, and Xiaomei can use these two The voucher is exchanged for a voucher with a denomination of x+1, and it is still placed in the position of the original two vouchers. Every time such an operation is performed, Xiaomei can obtain 1 yuan of bonus that can be used indefinitely.
Xiao Mei feels that the rewards are too fragrant, so she wants to get as much rewards as possible. May I ask how much rewards she can get.

Enter description

The first line of input contains only a positive integer n, which represents the number of vouchers owned by Xiaomei. (1<=n<=500) The
second line of input contains n positive integers, each integer x represents the denomination of a voucher, and this is also the order of the voucher discharged by the system. (1<=x<=100)

Output description

The output only contains an integer, which represents the maximum amount of bonus money that Xiaomei can get.

Instance

Input
5
1 1 1 1 1

Output
3

Ideas

It should be possible to use two stacks, but I didn’t write it out. I posted it by a big guy.

coding

n = int(input())
x = list(map(int, input().split()))
# 栈
stack = []
ans = 0
for i in range(n):
    while stack and x[i] == x[stack[-1]]:
        top = stack.pop()
        x[i] += 1
        ans += 1
    stack.append(i)
print(ans)
//感谢三百亿大佬

Insert picture description here

Happy time is always short, let's see you next time! ! !

good good study,day day up! (study hard, improve every day)

Foresee the funeral, please listen to the decomposition next time! ! ! !

Guess you like

Origin blog.csdn.net/qq_41606378/article/details/115274757