#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<bitset>
#include<algorithm>
#include<ctime>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 1e5 + 10;
const int maxm = (maxn<<5) + 5;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
int n, t, tot;
ll hpa, hpb, ata, atb;
ll sum[maxn];
struct node{ll hp; string choice;};
node kill_A(){
string ans;
int mid = lower_bound(sum + 1, sum + 1 + 100005, hpa) - sum;
ll hp = tot * atb + mid * ata;
if(sum[tot] - sum[mid] >= hpb){
for(int i = 1 ; i <= mid ; ++ i) ans += "A";
for(int i = mid + 1 ; i <= tot ; ++ i) ans += "B";
}
else{
for(int i = 1 ; i <= mid ; ++ i){
if(sum[mid] - hpa == i) ans += "B";
else ans += "A";
}
for(int i = mid + 1 ; i <= tot ; ++ i) ans += "B";
}
return node{hp, ans};
}
node kill_B(){
string ans;
int mid = lower_bound(sum + 1, sum + 1 + 100005, hpb) - sum;
ll hp = tot * ata + mid * atb;
ll extra = sum[mid] - hpb;
int temp = upper_bound(sum + 1, sum + 1 + 100005, extra) - sum - 1;
ll suf = sum[tot] - sum[mid];
if(suf + sum[temp] >= hpa){
for(int i = 1 ; i <= temp ; ++ i) ans += "A";
for(int i = temp + 1 ; i <= mid ; ++ i) ans += "B";
for(int i = mid + 1 ; i <= tot ; ++ i) ans += "A";
}
else{
ll sub = hpa - suf;
for(int i = 1 ; i <= mid ; ++ i){
if(sub - i > i || sub == i) sub -= i, ans += "A";
else ans += "B";
}
for(int i = mid + 1 ; i <= tot ; ++ i) ans += "A";
}
return node{hp, ans};
}
int main()
{
scanf("%d", &t);
for(int i = 1 ; i <= 1e5 ; ++ i) sum[i] = sum[i-1] + i;
while(t --){
scanf("%lld %lld %lld %lld", &hpa, &hpb, &ata, &atb);
tot = lower_bound(sum + 1, sum + 1 + 100005, hpa + hpb) - sum;
node x = kill_A(), y = kill_B();
if(x.hp > y.hp) cout << y.hp << ' ' << y.choice << endl;
else if(x.hp == y.hp){
if(x.choice < y.choice) cout << x.hp << ' ' << x.choice << endl;
else cout << y.hp << ' ' << y.choice << endl;
}
else cout << x.hp << ' ' << x.choice << endl;
}
return 0;
}
2018-2019 ACM-ICPC, Asia Jiaozuo Regional Contest(B - Ultraman vs. Aodzilla and Bodzilla)贪心
最新推荐文章于 2021-10-15 21:54:11 发布