ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

第一次ACM集训题 B题

2021-10-19 23:02:39  阅读:119  来源: 互联网

标签:paperD scissorsD paperB ACM scissorsB 第一次 rockD 集训 rockB


BaoBao and DreamGrid are playing a card game. Each player has nn cards in the beginning and there are three types of cards: rock, paper, and scissors.

The game consists of nn rounds. In each round, BaoBao will first play one of his remaining cards (this card is shown to both players). After that, DreamGrid can choose one of his remaining cards and play it (also shown to both players). The score of this round is calculated by referring to the following table:

DreamGrid \downarrow↓ \,\,\,\, BaoBao \rightarrow→ Rock Paper Scissors
Rock 0 -1 1
Paper 1 0 -1
Scissors -1 1 0

After the round, the two played cards are removed from the game. The score of the whole game is the sum of the score of each round.

BaoBao aims at minimizing the score of the whole game, while DreamGrid aims at maximizing it. Both players know the number of cards of each type his opponent and himself holds in the beginning. What's the final score of the game given that both of them take the best strategy?

Input

There are multiple test cases. The first line of the input contains an integer TT (1 \le T \le 10^31≤T≤103) indicating the number of test cases. For each test case:

The first line contains three integers b_rbr​, b_pbp​ and b_sbs​ (0 \le b_r, b_p, b_s \le 10^90≤br​,bp​,bs​≤109), indicating the number of rock, paper and scissors cards BaoBao has.

The second line contains three integers d_rdr​, d_pdp​ and d_sds​ (0 \le d_r, d_p, d_s \le 10^90≤dr​,dp​,ds​≤109), indicating the number of rock, paper and scissors cards DreamGrid has.

It's guaranteed that b_r + b_p + b_s = d_r + d_p + d_sbr​+bp​+bs​=dr​+dp​+ds​.

Output

For each test case output one line containing one integer indicating the final score of game.

 

#include<iostream>
using namespace std;
long long  sum[10000] = { 0 };
long long rockB, rockD, paperB, paperD, scissorsB, scissorsD;
int t = 0;

int main() {
    cin >> t;
    for (int i = 0;i < t;i++) {
        cin >> rockB >> paperB >> scissorsB;
        cin >> rockD >> paperD >> scissorsD;

        if (rockD > scissorsB) {
            sum[i] += scissorsB;
            rockD -= scissorsB;
            scissorsB = 0;
        }
        else {
            sum[i] += rockD;
            scissorsB -= rockD;
            rockD = 0;
        }
        if (paperD > rockB) {
            sum[i] += rockB;
            paperD -= rockB;
            rockB = 0;
        }
        else {
            sum[i] += paperD;
            rockB -= paperD;
            paperD = 0;
        }
        if (scissorsD > paperB) {
            sum[i] += paperB;
            scissorsD -= paperB;
            paperB = 0;
        }
        else {
            sum[i] += scissorsD;
            paperB -= scissorsD;
            scissorsD = 0;
        }

        if (rockD > 0 && rockB > 0) {
            if (rockD > rockB) {
                rockD -= rockB;
                rockB = 0;
            }
            else {
                rockB -= rockD;
                rockD = 0;
            }
        }

        if (paperD > 0 && paperB > 0) {
            if (paperD > paperB) {
                paperD -= paperB;
                paperB = 0;
            }
            else {
                paperB -= paperD;
                paperD = 0;
            }
        }
        if (scissorsD > 0 && scissorsB > 0) {
            if (scissorsD > scissorsB) {
                scissorsD -= scissorsB;
                scissorsB = 0;
            }
            else {
                scissorsB -= scissorsD;
                scissorsD = 0;
            }
        }
        sum[i] -= (rockD + rockB + paperD + paperB + scissorsD + scissorsB) / 2;
    }
    for (int i = 0;i < t;i++) {
        cout << sum[i] << endl;
    }
    return 0;
}

这题写的有点笨了,有人有更好的方法不

 

标签:paperD,scissorsD,paperB,ACM,scissorsB,第一次,rockD,集训,rockB
来源: https://www.cnblogs.com/ml-tiantong/p/15426903.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有