URAL - 2015 Zhenya moves from the dormitory

本文介绍了一个简单的算法,用于帮助用户根据预算和个人偏好选择合适的租房方案,包括独租公寓或与朋友合租。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

链接http://acm.timus.ru/problem.aspx?space=1&num=2015

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct Friend
{
	double mo;
	int ad;
}f[300];
struct house
{
	double mo;
	int ad;
	int ds;
}h[300];
int main()
{
	int i,j,n1,n2,m,flag=0,ad[5],t_f,t_h,t_ad=-1;
	double mo_m;
	scanf("%lf%d%d",&mo_m,&ad[1],&ad[2]);
	scanf("%d",&n1);
	for(i=1;i<=n1;i++)
	{
		scanf("%lf%d",&f[i].mo,&f[i].ad);
	}
	scanf("%d",&n2);
	for(i=1;i<=n2;i++)
	{
		scanf("%d%lf%d",&h[i].ds,&h[i].mo,&h[i].ad);
	}
	for(i=1;i<=n2;i++)
	{
		if(h[i].mo<=mo_m&&t_ad<ad[h[i].ds]+h[i].ad)
		{
			t_h=i;
			t_ad=ad[h[i].ds]+h[i].ad;
			flag=1;
		}
		if(h[i].ds==1) continue;
		if(h[i].mo/2.0>mo_m) continue;
		for(j=1;j<=n1;j++)
		{
			if(h[i].mo/2.0<=f[j].mo&&t_ad<h[i].ad+f[j].ad)
			{
				t_h=i;
				t_ad=h[i].ad+f[j].ad;
				t_f=j;
				flag=2;
			}
		}
	}
	if(flag==0) printf("Forget about apartments. Live in the dormitory.\n");
	else if(flag==1) printf("You should rent the apartment #%d alone.\n",t_h);
	else if(flag==2) printf("You should rent the apartment #%d with the friend #%d.\n",t_h,t_f);
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值