URAL 2015 Zhenya moves from the dormitory(水题)
来源:互联网 发布:55开淘宝店网址 编辑:程序博客网 时间:2024/05/19 18:17
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 mlines 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
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.
住宿舍问题,单独住有单独住的费用、value,合租value可加,然后具体水一水就好了。。。
当时这道水题的代码是我敲的,所以还是保留下,变量起的相当销魂,有木有!!!
#include <bits/stdc++.h>using namespace std;int alonecost,alone1value,alone2value;int friendcost[300],friendvalue[300],friendnum;int main (){ int n; while(~scanf("%d%d%d",&alonecost,&alone1value,&alone2value)) { scanf("%d",&friendnum); for(int i=1; i<=friendnum; i++) scanf("%d%d",&friendcost[i],&friendvalue[i]); scanf("%d",&n); int resnum=-1,resval=-1,resfrinum,resalOrdou; int alOrdou,cost,value; for(int i=1; i<=n; i++) { scanf("%d%d%d",&alOrdou,&cost,&value); if(cost<=alonecost)///自己住 { // cout<<"====\n"; if(alOrdou==1 && value+alone1value > resval) { // cout<<"PPPPPPP\n"; resnum=i,resval=value+alone1value,resalOrdou=1,resfrinum=-1; } else if(alOrdou==2 && value+alone2value > resval) { resnum=i,resval=value+alone2value,resalOrdou=1,resfrinum=-1; } } if(alOrdou==2 && alonecost>=(cost+1)/2) { //cout<<"++++++++\n"; for(int j=1; j<=friendnum; j++) { if(friendcost[j]>=(cost+1)/2 && friendvalue[j]+value>resval) { resnum=i,resval=friendvalue[j]+value,resfrinum=j,resalOrdou=2; } } } } if(resnum==-1) { printf("Forget about apartments. Live in the dormitory.\n"); } else { printf("You should rent the apartment #%d ",resnum); if(resalOrdou==2) { printf("with the friend #%d.\n",resfrinum); }else{ printf("alone.\n"); } } //cout<<resval<<endl; } 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(线段树+懒标记)
- URAL - 1788 On the Benefits of Umbrellas(水题)
- Go to study out of the dormitory again
- Goat in the Garden (ural 1348)
- (校赛)URAL 1998 The old Padawan
- Ural 1998 The old Padawan(二分)
- Ural 2018The Debut Album(DP)
- URAL 2018 The Debut Album(dp)
- URAL 2018. The Debut Album (dp)
- URAL 2018 The Debut Album(DP)
- Manifest merger failed : Attribute application@label value=(Dormitory) from AndroidManifest.xml:23:9
- Dormitory meetting.
- iPhone6无法开机、不能开机的解决方法
- 第九讲:c++的class
- GitHub上Daily项目的个人分析
- 应聘时最漂亮的回答
- Unity3D游戏美术全攻略:从入门到精通
- URAL 2015 Zhenya moves from the dormitory(水题)
- raknet 性能测试
- Centreon定义出图的风格
- 类中一定要有主方法吗?
- find_first_of()和 find_last_of() 【获取路径、文件名】
- 关于Unity渲染优化,你可能遇到这些问题
- 三角公式+菲涅尔公式
- Tomcat配置图片保存路径,图片不保存在项目路径下
- 你的开发为何如此低效?