ICode9

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

CF Round #592 (Div. 2) 题解

2019-10-14 21:58:20  阅读:498  来源: 互联网

标签:592 room floor Polycarp 题解 Nikolay rooms Div he


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

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

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

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

ICode9版权所有