【2018icpc焦作-B】Ultraman vs. Aodzilla and Bodzilla(思维)

题目链接

思路:

安排打怪顺序使得自己受伤最小,并输出字典序最小的打怪顺序。那么优先打完一个怪肯定是最好的,所以判断先击败A,再击败B和先B后A的最优解,然后需要考虑这样一件事,就是先A后B时,如果最后A剩的血量很少但此时攻击力很高,则这次攻击就浪费了一部分,可以用之前的一次攻击来替换,比如当前A剩余血量为5,此时攻击力为35.那么可以考虑是不是将30那次的攻击换成打B,这样的话A依旧是在35次击败,但是B可能就会早一点击败。先B后A的情况就需要判断比较多,因为牵扯到字典序最小,如果击败B时有浪费,就考虑将前面的一部分换成A,这样可以减小字典序。这里分两部分讨论,即将浪费的部分换成打A,能让A提前被击败或者与原来一样。两者是差不多的,只是前者在前面寻找合适的地方换成A时,需要保证换的位置的总和大于等于最后一次打A前的血量。

ac代码:

#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn=7e4;
ll sum[1000000];
char ans1[100000],ans2[100000];
int main(){
	for(int i=1;i<=maxn;i++){
		sum[i]=sum[i-1]+i;
	}
//	printf("%lld\n",sum[(int)maxn]); 
	int t;
	scanf("%d",&t);
	while(t--){
		ll ha,hb,aa,ab;
		scanf("%lld%lld%lld%lld",&ha,&hb,&aa,&ab);
		ll na=lower_bound(sum,sum+(int)maxn,ha)-sum; 
		ll nb=lower_bound(sum,sum+(int)maxn,sum[na]+hb)-sum-na;
		for(int i=1;i<=na;i++) ans1[i]='A';
		for(int i=na+1;i<=na+nb;i++) ans1[i]='B';
		ans1[na+nb+1]=0;
		ll res=na*(aa+ab)+nb*ab;
		ll tmp=sum[na]-ha;
		ll tmp2=sum[nb+na]-sum[na]-hb;
		if(tmp2-nb-na+tmp>=0) res-=ab,ans1[tmp]='B',ans1[na+nb]=0;
//		tmp>nb+na-tmp2
		
		nb=lower_bound(sum,sum+(int)maxn,hb)-sum;
		na=lower_bound(sum,sum+(int)maxn,sum[nb]+ha)-sum-nb;
		for(int i=1;i<=nb;i++) ans2[i]='B';
		for(int i=nb+1;i<=na+nb;i++) ans2[i]='A';
		ans2[na+nb+1]=0;
		ll res2=nb*(aa+ab)+na*aa;
		tmp=sum[nb]-hb;
		tmp2=sum[nb+na]-sum[nb]-ha;
		
		if(tmp2-na-nb+tmp>=0){
			res2-=aa,ans2[na+nb]=0;
			ll tt=tmp2-na-nb+tmp;
			int las=0;
			for(int i=1;;i++){
				if(i>tmp){
					if(tmp<=tt) break;
//					las+tmp-tt
					ans2[las]='B';
					ans2[tmp+las-tt]='A';
					break;
				}
				las=i;
				ans2[i]='A';
				tmp-=i;
			}
//			ans2[tmp]='A'
		} 
		else{
			for(int i=1;;i++){
				if(i>tmp) break;
				ans2[i]='A';
				tmp-=i;
			}
		}
		if(res<res2) printf("%lld %s\n",res,ans1+1);
		else if(res2<res)printf("%lld %s\n",res2,ans2+1);
		else{
			printf("%lld ",res);
			if(strcmp(ans1+1,ans2+1)<0) puts(ans1+1);
			else puts(ans2+1);
		}
	}
	 
	
	
	return 0;
}
/*
1100
4 9 2 1
4 11 2 1
4 13 2 1
5 15 5 25
5 15 25 5
10 6 1 2
10 5 1 2
11 5 1 2
*/

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值