URAL 2015. Zhenya moves from the dormitory
来源:互联网 发布:开通淘宝网店多少费用 编辑:程序博客网 时间:2024/05/07 02:52
2015. Zhenya moves from the dormitory
Time limit: 1.0 second
Memory limit: 64 MB
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 numberi alone, output “You should rent the apartment #i alone.”. If he should share an apartment numberi 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
10000 50 70110000 10021 10000 2002 30000 500
You should rent the apartment #1 alone.
30000 0 1110000 100131 20000 20002 30000 20002 10000 1001
You should rent the apartment #3 with the friend #1.
1000 0 0011 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 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
- URAL 2015. Zhenya moves from the dormitory
- URAL 2015 Zhenya moves from the dormitory(水题)
- URAL2015 Zhenya moves from the dormitory (暴力)
- URAL 2014 Zhenya moves from parents 线段树
- URAL 2014 Zhenya moves from parents --线段树
- URAL 2014 Zhenya moves from parents 线段树
- Gym100507C--Zhenya moves from parents(线段树+懒标记)
- Go to study out of the dormitory again
- Manifest merger failed : Attribute application@label value=(Dormitory) from AndroidManifest.xml:23:9
- Dormitory meetting.
- Ural 1017 The Staircases
- ural 1017. The Staircases
- URAL_2014_Zhenya moves from parents_线段树
- URAL 1015. Test the Difference!
- ural 1015 Test the Difference!
- URAL 1779. The Great Team
- ural 1998 The old Padawan
- URAL 1998 The old Padawan
- poj----Anagram Groups
- URAL2018——The Debut Album(DP)
- 大型分布式网站的架构提供的各个服务
- 提高pip下载速度
- phpstudy搭建DVWA
- URAL 2015. Zhenya moves from the dormitory
- 【C#基础】——面向对象
- VPN说明书
- 15 个 Android 通用流行框架大全
- Arduino Uno + RFID 读取 把你的门禁卡读取看看有什么秘密
- 身份证纹理去除思路探究
- reactnative LayoutAnimation 在android中没效果
- 杭电acm 2063 过山车
- hdu 2222 Keywords Search