其他分享
首页 > 其他分享> > CF Round #592 (Div. 2) 题解

CF Round #592 (Div. 2) 题解

作者:互联网

Problem - A

Tomorrow is a difficult day for Polycarp: he has to attend \(a\) lectures and \(b\) practical classes at the university! Since Polycarp is a diligent student, he is going to attend all of them.

While preparing for the university, Polycarp wonders whether he can take enough writing implements to write all of the lectures and draw everything he has to during all of the practical classes. Polycarp writes lectures using a pen (he can't use a pencil to write lectures!); he can write down \(c\) lectures using one pen, and after that it runs out of ink. During practical classes Polycarp draws blueprints with a pencil (he can't use a pen to draw blueprints!); one pencil is enough to draw all blueprints during \(d\) practical classes, after which it is unusable.

Polycarp's pencilcase can hold no more than \(k\) writing implements, so if Polycarp wants to take \(x\) pens and \(y\) pencils, they will fit in the pencilcase if and only if \(x+y \leq k\).

Now Polycarp wants to know how many pens and pencils should he take. Help him to determine it, or tell that his pencilcase doesn't have enough room for all the implements he needs tomorrow!

Note that you don't have to minimize the number of writing implements (though their total number must not exceed \(k\)).

题意

给定 \(a,b,c,d,k\)
求一对 \(x,y\) 使 \(cx \geq a,dy \geq b\) 且 \(x+y \leq k\)

代码

#include <bits/stdc++.h>
int t,a,b,c,d,k;
int main() {
    for (scanf("%d",&t);t--;) {
        int x = -1,y = -1;
        scanf("%d%d%d%d%d",&a,&b,&c,&d,&k);
        for (int i = 0;i <= k;i++)
            for (int j = 0;i+j <= k;j++)
                if (c*i >= a && d*j >= b) {
                    x = i,y = j;
                    break;
                }
        if (x == -1) printf("-1\n");
        else printf("%d %d\n",x,y);
    }
    return 0;
}

Problem - B

Nikolay lives in a two-storied house. There are \(n\) rooms on each floor, arranged in a row and numbered from one from left to right. So each room can be represented by the number of the floor and the number of the room on this floor (room number is an integer between \(1\) and \(n\)).

If Nikolay is currently in some room, he can move to any of the neighbouring rooms (if they exist). Rooms with numbers \(i\) and \(i+1\) on each floor are neighbouring, for all \(1≤i≤n−1\). There may also be staircases that connect two rooms from different floors having the same numbers. If there is a staircase connecting the room \(x\) on the first floor and the room \(x\) on the second floor, then Nikolay can use it to move from one room to another.

The picture illustrates a house with \(n=4\). There is a staircase between the room \(2\) on the first floor and the room \(2\) on the second floor, and another staircase between the room \(4\) on the first floor and the room \(4\) on the second floor. The arrows denote possible directions in which Nikolay can move. The picture corresponds to the string "0101" in the input.

Nikolay wants to move through some rooms in his house. To do this, he firstly chooses any room where he starts. Then Nikolay moves between rooms according to the aforementioned rules. Nikolay never visits the same room twice (he won't enter a room where he has already been).

Calculate the maximum number of rooms Nikolay can visit during his tour, if:
·he can start in any room on any floor of his choice,
·and he won't visit the same room twice.

标签:592,room,floor,Polycarp,题解,Nikolay,rooms,Div,he
来源: https://www.cnblogs.com/lrj124/p/11674327.html