hdu 4296 Buildings(外一篇:hdu 4310 Hero)

11 篇文章 0 订阅

http://acm.hdu.edu.cn/showproblem.php?pid=42

分析:条件:A.w+A.s<B.w+b.s

具体分析:http://blog.csdn.net/acm_ted/article/details/7984935

1) a=sum-si;b=sum+wi-sj;

           交换两个板的位置

2)b'=sum-sj;a'=sum+wj-si;

          如果1优于2,求解得有效的条件为wj-si>wi-sj。


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

const int NM=100005;
struct Build{
	int x,y;
}t[NM];

bool comp(struct Build A,struct Build B)
{
	if(A.x+A.y<B.x+B.y) return 1;
	else return 0;
}

int main()
{
	__int64 sum,ans;
	int n,i;
	while(cin>>n)
	{
		for(i=0;i<n;i++)
			cin>>t[i].x>>t[i].y;
		sort(t,t+n,comp);
		sum=ans=0;
		for(i=0;i<n;i++)
		{
			if(sum-t[i].y>ans)
				ans=sum-t[i].y;
			sum+=t[i].x;
		}
		printf("%I64d\n",ans);
	}
	return 0;
}

http://acm.hdu.edu.cn/showproblem.php?pid=4310

分析:A的结果优于B,即:sum*hpA+(sum-dpA)*hpB<sum*hpB+(sum-dpB)*hpA

即:sum*(hpA-hpB)+sum*(hpB-hpA)-dpA*hpB<-dpB*hpA

化简得:dpA*hpB>dpB*hpA(dpA/hpA>dpB/hpB)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值