Input
Output
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. |
Hint
/* * @Author: lyuc * @Date: 2017-04-30 15:11:54 * @Last Modified by: lyuc * @Last Modified time: 2017-04-30 15:32:17 */ /** * 题意:Zhenya想租房子,可以和朋友合租,也可以自己租,自己租的时候要付全部的租金,和朋友合租的时候要严格的 * 一人一半 * * 思路:暴力,读错题了,应该是自己住的单间的时候快乐值是:快乐值1+酒店快乐值,自己住双人间的时候快乐值是: * 快乐值2+酒店快乐值,和朋友合租的时候快乐值是:朋友的快乐值+酒店快乐值 */ #include <iostream> #include <stdio.h> using namespace std; struct Fr{ int pay,hap; }fr[300]; struct Ho{ int id,pay,hap; }ho[300]; int pay,hap1,hap2; int n,m; int main(){ // freopen("in.txt","r",stdin); scanf("%d%d%d",&pay,&hap1,&hap2); scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d%d",&fr[i].pay,&fr[i].hap); } scanf("%d",&m); for(int i=0;i<m;i++){ scanf("%d%d%d",&ho[i].id,&ho[i].pay,&ho[i].hap); } int maxhap=-1; int maxho=-1; int maxfr=-1; for(int i=0;i<m;i++){ if(ho[i].id==1){ if(pay>=ho[i].pay){ if(hap1+ho[i].hap>maxhap){ maxhap=hap1+ho[i].hap; maxho=i; maxfr=-1; } } }else if(ho[i].id==2){ if(pay>=ho[i].pay){ if(hap2+ho[i].hap>maxhap){ maxhap=hap2+ho[i].hap; maxho=i; maxfr=-1; } } for(int j=0;j<n;j++){ if(min(pay,fr[j].pay)*2>=ho[i].pay){ if(fr[j].hap+ho[i].hap>maxhap){ maxhap=fr[j].hap+ho[i].hap; maxho=i; maxfr=j; } } } } } if(maxho==-1){ puts("Forget about apartments. Live in the dormitory."); }else{ if(maxfr==-1){ printf("You should rent the apartment #%d alone.\n",maxho+1); }else{ printf("You should rent the apartment #%d with the friend #%d.\n",maxho+1,maxfr+1); } } return 0; }
D - Zhenya moves from the dormitory URAL - 2015
原文:http://www.cnblogs.com/wuwangchuxin0924/p/6789553.html