2018-2019 ACM-ICPC, Asia Jiaozuo Regional Contest(B - Ultraman vs. Aodzilla and Bodzilla)贪心

#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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值