A. Shovels and Swords

这篇博客探讨了一款计算机游戏中的资源管理问题。玩家Polycarp可以通过合成铲子和剑来获取绿宝石。每把剑需要2个钻石和1根木棍,每个铲子需要2个木棍和1个钻石。玩家的目标是通过最优的合成策略来最大化绿宝石的数量。文章提供了一个简单的算法,根据木棍和钻石的相对数量来确定最佳合成方案,并给出了若干示例测试用例来说明这个策略的运用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Shovels and Swords
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Polycarp plays a well-known computer game (we won’t mention its name). In this game, he can craft tools of two types — shovels and swords. To craft a shovel, Polycarp spends two sticks and one diamond; to craft a sword, Polycarp spends two diamonds and one stick.

Each tool can be sold for exactly one emerald. How many emeralds can Polycarp earn, if he has a sticks and b diamonds?

Input
The first line contains one integer t (1≤t≤1000) — the number of test cases.

The only line of each test case contains two integers a and b (0≤a,b≤109) — the number of sticks and the number of diamonds, respectively.

Output
For each test case print one integer — the maximum number of emeralds Polycarp can earn.

Example
inputCopy
4
4 4
1000000000 0
7 15
8 7
outputCopy
2
0
7
5
Note
In the first test case Polycarp can earn two emeralds as follows: craft one sword and one shovel.

In the second test case Polycarp does not have any diamonds, so he cannot craft anything.

#include<iostream>
using namespace std;
int main()
{
	int n,a,b;
	cin>>n;
	while(n--)
	{
		    cin>>a>>b;
		    if(a<(a+b)/3)
		    cout<<a<<endl;
		    else
		    if(b<(a+b)/3)
		    cout<<b<<endl;
		    else
		    cout<<(a+b)/3<<endl;
	}
}
min Z = 154 * ∑(i=1 to 10)(j=1 to 5) C_ij * X_ij 约束条件: 1. 每个卸点j的产量要求: ∑(i=1 to 10) X_ij >= d_j / 154, j=1,2,3,4,5 2. 时间约束: 5 * K_ij <= (15/7)*C_ij + 8, ∀i,j 3. 质量约束(仅矿石卸点j=1,2,5): 0.285 * ∑(i) X_i1 <= ∑(i) X_i1 * e_i <= 0.305 * ∑(i) X_i1 (对于j=1) 0.285 * ∑(i) X_i2 <= ∑(i) X_i2 * e_i <= 0.305 * ∑(i) X_i2 (对于j=2) 0.285 * ∑(i) X_i5 <= ∑(i) X_i5 * e_i <= 0.305 * ∑(i) X_i5 (对于j=5) 4. 铲位数量约束: ∑(i=1 to 10) a_i <= 7 5. 物料约束(铲位i的矿石和岩石总量约束): ∑(j in {1,2,5}) X_ij <= D_i^{(1)} / 154 (矿石卸点) ∑(j in {3,4}) X_ij <= D_i^{(2)} / 154 (岩石卸点) 6. 铲位使用约束(如果铲位i没有电铲,则不能运输): ∑(j=1 to 5) X_ij <= (D_i^{(1)} + D_i^{(2)}) / 154 * a_i ∑(i=1 to 10)(j=1 to 5) K_ij<=20 K_ij=((15/7)*C_ij + 8)*X_ij/475 7. 变量类型: a_i &isin; {0,1} (二进制变量) X_ij >= 0 (连续变量) 数据: C_ij 矩阵(10个铲位i,5个卸点j): j=1 j=2 j=3 j=4 j=5 i=1: 5.26, 1.90, 5.89, 0.64, 4.42 i=2: 5.19, 0.99, 5.61, 1.76, 3.86 i=3: 4.21, 1.90, 5.61, 1.27, 3.72 i=4: 4.00, 1.13, 4.56, 1.83, 3.16 i=5: 2.95, 1.27, 3.51, 2.74, 2.25 i=6: 2.74, 2.25, 3.65, 2.60, 2.81 i=7: 2.46, 1.48, 2.46, 4.21, 0.78 i=8: 1.90, 2.04, 2.46, 3.72, 1.62 i=9: 0.64, 3.09, 1.06, 5.05, 1.27 i=10:1.27, 3.51, 0.57, 6.10, 0.50 e_i(铁含量,以小数表示): i=1:0.30, i=2:0.28, i=3:0.29, i=4:0.32, i=5:0.31, i=6:0.33, i=7:0.32, i=8:0.31, i=9:0.33, i=10:0.31 D_i^{(1)}(矿石总量): i=1:9500, i=2:10500, i=3:10000, i=4:10500, i=5:11000, i=6:12500, i=7:10500, i=8:13000, i=9:13500, i=10:12500 D_i^{(2)}(岩石总量): i=1:12500, i=2:11000, i=3:13500, i=4:10500, i=5:11500, i=6:13500, i=7:10500, i=8:11500, i=9:13500, i=10:12500 d_j(卸点产量要求): j=1:12000, j=2:13000, j=3:13000, j=4:19000, j=5:13000 添加∑(j=1 to 5)Xij<=96(i=1,2,3,4,5,6,7,8,9,10)(i=1 to 10)Xij<=160(i=1,2,3,4,5) 给出MATLAB求解代码
最新发布
07-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值