Gym 100507D Zhenya moves from the dormitory (模拟)

Zhenya moves from the dormitory

题目链接:

http://acm.hust.edu.cn/vjudge/contest/126546#problem/D

Description

After moving from his parents’ place Zhenya has been living in the University dormitory for a month. However, he got pretty tired of the curfew time and queues to the shower room so he took a fancy for renting an apartment. It turned out not the easiest thing in the world to make a choice. One can live in a one bedroom apartment or in a two bedroom apartment, alone or share it with a friend. Zhenya can afford to rent an apartment of any type alone, but he can share only a two bedroom apartment. If two people share an apartment, each pays half of the rent. Every apartment has its own advantages like part of the town, floor, view from the windows, etc., which Zhenya is going to take into account to make a decision. Besides that, his friends, he’s ready to share an apartment with, also have certain advantages. For example, Igor is a good cook, Dima is tidy, Kostya is a good cook and at the same time can explain how to solve functional analysis problems. And do not forget that living alone has its own bright sides. Zhenya has already prepared the list of suitable apartments and possible housemates. Zhenya has estimated in units the advantages of each apartment and each friend and also the advantages of living alone. Besides, he knows the maximum sum of money he and each of his friends is ready to pay for the apartment. Help Zhenya to make a decision.

Input

The first line contains three integers: the maximum sum Zhenya is ready to pay monthly, the advantages of living alone in a one bedroom apartment and the advantages of living alone in a two bedroom apartment. The second line contains an integer 𝑛 that is the number of Zhenya’s friends (0 ≤ 𝑛 ≤ 256). Next 𝑛 lines describe the friends, two integers in every line: the maximum sum the corresponding friend is ready to pay monthly and the advantages of sharing an apartment with him. The next line contains an integer 𝑚 that is the number of suitable apartments (1 ≤ 𝑚 ≤ 256). Next 𝑚 lines describe the apartments, three integers in every line: the number of bedrooms in an apartment (1 or 2), monthly rent and the advantages of living there. All the advantages are estimated in the same units and lie in the range from 0 to 100 000. All sums of money are in rubles and lie in the range from 1 to 100 000.

Output

Output the variant with maximum sum of advantages, Zhenya (and his friend in case of sharing apartments) can afford. If Zhenya should rent an apartment number 𝑖 alone, output “You should rent the apartment #i alone.”. If he should share an apartment number 𝑖 with a friend 𝑗 output “You should rent the apartment #i with the friend #j.”. Friends and apartments are numbered from 1 in order they are given in the input. If there are several optimal alternatives, output any of them. If Zhenya can’t afford to rent any apartment at all, output “Forget about apartments. Live in the dormitory.”.

Examples

test answer 10000 50 70 1 10000 100 2 1 10000 200 2 30000 500 You should rent the apartment #1 alone. 30000 0 1 1 10000 1001 3 1 20000 2000 2 30000 2000 2 10000 1001 You should rent the apartment #3 with the friend #1. 1000 0 0 0 1 1 10000 1000 Forget about apartments. Live in the dormitory.

Explanations

In the first example Zhenya can’t afford even to share the second apartment. That is why he has to rent the first one. The sum of advantages in this case will be 250 (50 + 200). In the second example Zhenya can afford any apartment but he can share only the third one. If he chooses this variant, the sum of advantages will be 2002 (1001 + 1001), and if he chooses to live alone it will not be more than 2001 (1 + 2000 in case of living alone in the second apartment). In the third example Zhenya can’t afford the only possible variant.
##题意: 一个人要租房,可以选择租单人间,也可以自己租双人间或者合租双人间. 给出自己的钱和单租的满意度.(合租没有满意度). 给出n个朋友的钱和可能提供的满意度. 给出每间房的类型、价格、满意度. 求最大满意度的租房方式.
##题解: 枚举每间房和每个舍友,判断能否租房以及比较满意度. 注意细节的处理:区别自己租双人间、合租双人间.(输出方式不一样)
##代码: ``` cpp #include #include #include #include #include #include #include #include #include #define LL long long #define eps 1e-8 #define maxn 550 #define mod 100000007 #define inf 0x3f3f3f3f #define IN freopen("in.txt","r",stdin); using namespace std;

int my_money, adv1, adv2;
int n,m;
struct node1{
int money;
int adv;
}roommate[300];
struct node2{
int type;
int cost;
int adv;
}room[300];

int main(int argc, char const *argv[])
{
//IN;

while(scanf("%d %d %d", &my_money, &adv1, &adv2) != EOF)
{
    cin >> n;
    for(int i=1; i<=n; i++) {
        scanf("%d %d", &roommate[i].money, &roommate[i].adv);
    }
    cin >> m;
    for(int i=1; i<=m; i++) {
        scanf("%d %d %d", &room[i].type, &room[i].cost, &room[i].adv);
    }

    int ans = -inf;
    int room_id, mate;

    for(int i=1; i<=m; i++) {
        if(room[i].cost <= my_money) {
            if(room[i].type == 1 && room[i].adv+adv1 > ans) {
                ans = room[i].adv+adv1;
                room_id = i;
            }
            if(room[i].type == 2 && room[i].adv+adv2 > ans) {
                ans = room[i].adv+adv2;
                room_id = i;
                mate = -1;
            }
        }

        if(room[i].type == 1) continue;
        for(int j=1; j<=n; j++) {
            if(roommate[j].money*2 >= room[i].cost && my_money*2 >= room[i].cost
                && room[i].adv+roommate[j].adv > ans) {
                    ans = room[i].adv+roommate[j].adv;
                    room_id = i;
                    mate = j;
            }
        }
    }

    if(ans == -inf) printf("Forget about apartments. Live in the dormitory.\n");
    else {
        if(room[room_id].type == 1) printf("You should rent the apartment #%d alone.\n", room_id);
        else {
            if(mate == -1) printf("You should rent the apartment #%d alone.\n", room_id);
            else printf("You should rent the apartment #%d with the friend #%d.\n", room_id, mate);
        }
    }
}

return 0;

}

posted @ 2016-08-07 12:29  Sunshine_tcf  阅读(327)  评论(0编辑  收藏  举报