SDKD 2017 Spring Team Training B--D - Zhenya moves from the dormitory

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  n that is the number of Zhenya’s friends (0 ≤ n ≤ 256). Next  n 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  m that is the number of suitable apartments (1 ≤ m ≤ 256). Next  m 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  ialone, output “You should rent the apartment #i alone.”. If he should share an apartment number  i with a friend  j 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.”.
Example
input output
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.

Notes

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.

解题思路:
题意为:一个人选择不同公寓,并与不同朋友住或自己住有不同的幸福值,求出最大值得情况,

题目不难,只要题意读清句没问题,NOTE:第一行的后两个值为自己单独住单人房和单独住双人房的幸福值;他可以自己住双人房;要考虑到拼房时,如果价钱是奇数的情况;

代码:

#include<iostream>
#include<cstdio>
using namespace std;
#define N 257
#define inf -1000000002
struct pengyou{
    int m,hap;
};
struct rom{
    int typ,m,hap;
};
int main()
{
    //freopen("aaa.txt","r",stdin);
    pengyou p[N];
    rom r[N];
    int n,m,mym,hap1,hap2,i,j;
    scanf("%d%d%d",&mym,&hap1,&hap2);
    scanf("%d",&n);
    for(i=0;i<n;i++)
    scanf("%d%d",&p[i].m,&p[i].hap);
    scanf("%d",&m);
    for(i=0;i<m;i++)
    scanf("%d%d%d",&r[i].typ,&r[i].m,&r[i].hap);
    int v1,v2,flag1,flag2p,flag2r;
    v1=v2=inf;
    for(i=0;i<m;i++)
    {
        if(r[i].typ==1) {
            if(r[i].m<=mym)
            {
                if(v1<r[i].hap+hap1) {v1=r[i].hap+hap1; flag1=i+1; }
            }
        }
        else {
            if(r[i].m<=mym)
            {
                if(v1<r[i].hap+hap2) {v1=r[i].hap+hap2; flag1=i+1; }
            }
            for(j=0;j<n;j++)
            {
                int x=r[i].m/2+r[i].m%2;
                if(mym>=x&&p[j].m>=x)
                {
                    if(v2<r[i].hap+p[j].hap) {v2=r[i].hap+p[j].hap; flag2r=i+1;flag2p=j+1;}
                }
            }
        }
    }
    if(v1!=inf||v2!=inf){
        if(v1>=v2) cout<<"You should rent the apartment #"<<flag1<<" alone."<<endl;
        else cout<<"You should rent the apartment #"<<flag2r<<" with the friend #"<<flag2p<<"."<<endl;
    }
    else {cout<<"Forget about apartments. Live in the dormitory."<<endl;}
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值