第一次ACM集训题 B题
2021/10/19 23:10:16
本文主要是介绍第一次ACM集训题 B题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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; }
这题写的有点笨了,有人有更好的方法不
这篇关于第一次ACM集训题 B题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-01UniApp 中组件的生命周期是多少-icode9专业技术文章分享
- 2024-11-01如何使用Svg Sprite Icon简化网页图标管理
- 2024-10-31Excel数据导出课程:新手从入门到精通的实用教程
- 2024-10-31Excel数据导入课程:新手入门指南
- 2024-10-31RBAC的权限课程:新手入门教程
- 2024-10-31Svg Sprite Icon课程:新手入门必备指南
- 2024-10-31怎么配置 L2TP 允许多用户连接-icode9专业技术文章分享
- 2024-10-31怎么在FreeBSD上 安装 OpenResty-icode9专业技术文章分享
- 2024-10-31运行 modprobe l2tp_ppp 时收到“module not found”消息提醒是什么-icode9专业技术文章分享
- 2024-10-31FreeBSD的下载命令有哪些-icode9专业技术文章分享