URAL 2015. Zhenya moves from the dormitory

2015. Zhenya moves from the dormitory

Time limit: 1.0 second
Memory limit: 64 MB
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 i alone, 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.”.

Samples

inputoutput
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.
Problem Author: Eugene Kurpilyansky

Problem Source: NEERC 2014, Eastern subregional contest

这代码敲得我自己都得加注释。。。

开始写的很麻烦 彻底分成了三种

比赛时改了两个半小时也没改出来= =

改后用ans存所有情况下的优点最多的

然后全用t存屋子的号

#include<bits/stdc++.h>
struct node
{
    int peo;
    int pri,adv;
   //int sad11 ,sad12,sad22;//sad11 1   sad22 2zhu2   sad12
} x[300];
struct nodefri
{
    int num;
    int mon;
    int adv;
} z[300];
int main()
{
    int i,j;
    int m,n;
    int a,b,money;
    scanf("%d%d%d",&money,&a,&b);
    scanf("%d",&n);
    for(i=0; i<n; i++) //n朋友的个数   m屋子数
    {
        scanf("%d%d",&z[i].mon,&z[i].adv);
        z[i].num=i+1;
    }//z是朋友
    scanf("%d",&m);
    for(i=0; i<m; i++)
    {
        scanf("%d%d%d",&x[i].peo,&x[i].pri,&x[i].adv);
        x[i].sad11=0,x[i].sad12=0,x[i].sad22=0;
    }
    int f=0;
    int ans=-1,t=-1;
    for(i=0; i<m; i++)
    {
        if(x[i].peo==1)
        {
            if(money>=x[i].pri)
            {
                f=1;
                if(ans<x[i].adv+a)
                {
                    ans=x[i].adv+a;
                    t=i+1;
                }
            }
        }
        else
        {
            if(money>=x[i].pri)
            {
                f=1;
                if(ans<x[i].adv+b)
                {
                    ans=x[i].adv+b;
                    t=i+1;
                }
            }
        }
    }
    int f22=-1;
    for(i=0; i<n; i++) //朋友
    {
        for(j=0; j<m; j++) //双人间
        {
            if(x[j].peo==2)
            {
                if(money>=((x[j].pri*1.0)/2)&&z[i].mon>=((x[j].pri*1.0)/2))
                {
                    if(x[j].adv+z[i].adv>ans)
                    {
                        f=2;
                        ans=x[j].adv+z[i].adv;
                        f22=i+1;
                        t=j+1;
                    }
                }
            }
        }
    }
    if(f==0) printf("Forget about apartments. Live in the dormitory.\n");
    else
    {
        if(f==1)
        {
            printf("You should rent the apartment #%d alone.\n",t);
        }
        else
//            (ma22>=ma11&&ma22>=ma12)
        {
            printf("You should rent the apartment #%d with the friend #%d.\n",t,f22);
        }
    }
    return 0;

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
用代码解决这个问题The program committee of the school programming contests, which are often held at the Ural State University, is a big, joyful, and united team. In fact, they are so united that the time spent together at the university is not enough for them, so they often visit each other at their homes. In addition, they are quite athletic and like walking. Once the guardian of the traditions of the sports programming at the Ural State University decided that the members of the program committee spent too much time walking from home to home. They could have spent that time inventing and preparing new problems instead. To prove that, he wanted to calculate the average distance that the members of the program committee walked when they visited each other. The guardian took a map of Yekaterinburg, marked the houses of all the members of the program committee there, and wrote down their coordinates. However, there were so many coordinates that he wasn't able to solve that problem and asked for your help. The city of Yekaterinburg is a rectangle with the sides parallel to the coordinate axes. All the streets stretch from east to west or from north to south through the whole city, from one end to the other. The house of each member of the program committee is located strictly at the intersection of two orthogonal streets. It is known that all the members of the program committee walk only along the streets, because it is more pleasant to walk on sidewalks than on small courtyard paths. Of course, when walking from one house to another, they always choose the shortest way. All the members of the program committee visit each other equally often. Input The first line contains the number n of members of the program committee (2 ≤ n ≤ 105). The i-th of the following n lines contains space-separated coordinates xi, yi of the house of the i-th member of the program committee (1 ≤ xi, yi ≤ 106). All coordinates are integers. Output Output the average distance, rounded down to an integer, that a member of the program committee walks from his house to the house of his colleague.
最新发布
05-26

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值