Potion

题目链接
BaoBao is brewing a magical potion. To brew this potion, n types of ingredients, whose rank ranges from 1 to n, is needed. More precisely, for all 1 <= i <= n, BaoBao needs at least ai pieces of rank-i ingredients to make the potion, while he only has bi pieces of these ingredients in his storeroom.

Fortunately, BaoBao is able to downgrade a higher rank ingredient to a lower rank one (this operation can be performed any number of times, including zero time). Is it possible that BaoBao can make the potion using the ingredients in his storeroom?

Input
There are multiple test cases. The first line of the input contains an integer T (about 100), indicating the number of test cases. For each test case:

The first line contains an integer n (1 <= n <= 100), indicating the number of types of ingredients.

The second line contains n integers a1,a2,,,an (1 <= ai <= 1000000000), where ai indicates the number of rank-i ingredients needed.

The third line contains n integers b1,b2,,,bn (1 <= bi <= 1000000000), where bi indicates the number of rank-i ingredients BaoBao has in his storeroom.

Output
For each test case output one line. If BaoBao is able to brew the potion, output “Yes” (without quotes), otherwise output “No” (without quotes).

Sample Input
2
3
3 3 1
1 2 5
3
3 1 2
5 2 1

Sample Output
Yes
No

Hint
For the first sample test case, BaoBao can downgrade one rank-3 ingredient to a rank-2 ingredient, and downgrade two rank-3 ingredients to two rank-1 ingredients.

题解:
按等级给你一堆材料的需求量,再按等级给出你有多少材料,你所拥有的材料是可以降级的,将级没有限制,降几级,降几次都可以,然后问你材料够不够,从后往前扫,多出来的能降级就降级,一旦不够了就跳出

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL t,n,f,a[105],b[105];
int main(){
	ios :: sync_with_stdio(false);
	cin.tie(0);
	cin >> t;
	while(t--){
		cin >> n;
		for(int i = 1;i <= n;i++) cin >> a[i];
		for(int i = 1;i <= n;i++) cin >> b[i];
		f = 1;
		for(int i = n;i >= 1;i--){
			if(b[i] < a[i]){
				f = 0;
				cout << "No" << endl;
				break;
			}
			else{
				b[i - 1] += b[i] - a[i];
			}
		}
		if(f == 1){
			cout << "Yes" << endl;
		}
	} 
	return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是制作背包的基本思路: 1. 创建一个背包界面,包含物品的图标、名称、数量等信息。 2. 创建一个物品类,用来存储每个物品的信息,包括编号、名称、图标、数量等信息。 3. 在游戏启动时读取text文件中的物品信息,将每个物品的信息存储到物品类中,并将物品类存储到一个数组中。 4. 点击背包界面中的物品图标时,根据物品编号在物品数组中查找对应的物品信息,并在背包界面中显示该物品的详细信息。 5. 可以在背包界面中拖拽物品图标进行交换位置,或者丢弃物品。 下面是一个示例代码,可以参考一下: ```csharp using UnityEngine; using UnityEngine.UI; using System.Collections.Generic; // 物品类 public class Item { public int id; // 物品编号 public string name; // 物品名称 public Sprite icon; // 物品图标 public int count; // 物品数量 public int price; // 物品价格 public int hp; // 恢复生命值 public int mp; // 恢复魔法值 // 从text文件中读取物品信息 public static Item Load(string line) { string[] data = line.Split(','); Item item = new Item(); item.id = int.Parse(data[0]); item.name = data[1]; item.icon = Resources.Load<Sprite>(data[2]); item.count = int.Parse(data[3]); item.price = int.Parse(data[4]); item.hp = int.Parse(data[5]); item.mp = int.Parse(data[6]); return item; } } // 背包界面 public class Backpack : MonoBehaviour { public Image itemIcon; // 物品图标 public Text itemName; // 物品名称 public Text itemCount; // 物品数量 public Text itemPrice; // 物品价格 public Text itemHp; // 恢复生命值 public Text itemMp; // 恢复魔法值 public Transform content; // 背包物品容器 private List<Item> items = new List<Item>(); // 物品列表 // 游戏启动时加载物品信息 private void Start() { TextAsset asset = Resources.Load<TextAsset>("items"); string[] lines = asset.text.Split('\n'); foreach (string line in lines) { Item item = Item.Load(line); items.Add(item); } } // 点击物品图标时显示该物品的详细信息 public void OnItemClick(int id) { Item item = items.Find(x => x.id == id); itemIcon.sprite = item.icon; itemName.text = item.name; itemCount.text = "数量:" + item.count; itemPrice.text = "价格:" + item.price; itemHp.text = "恢复生命值:" + item.hp; itemMp.text = "恢复魔法值:" + item.mp; } // 向背包中添加物品 public void AddItem(int id, int count) { Item item = items.Find(x => x.id == id); if (item != null) { item.count += count; UpdateItem(item); } } // 从背包中移除物品 public void RemoveItem(int id, int count) { Item item = items.Find(x => x.id == id); if (item != null) { item.count -= count; UpdateItem(item); } } // 更新物品信息 private void UpdateItem(Item item) { foreach (Transform child in content) { ItemSlot slot = child.GetComponent<ItemSlot>(); if (slot.itemId == item.id) { slot.UpdateItem(item); break; } } } } // 背包中的物品槽 public class ItemSlot : MonoBehaviour { public Image itemIcon; // 物品图标 public Text itemCount; // 物品数量 public int itemId; // 物品编号 public int itemAmount; // 物品数量 // 更新物品信息 public void UpdateItem(Item item) { itemId = item.id; itemAmount = item.count; itemIcon.sprite = item.icon; itemCount.text = item.count.ToString(); } } ``` 使用方法: 1. 创建一个UI界面,添加上述代码中的Backpack组件。 2. 创建一个TextAsset资源,命名为items,并将物品信息按照示例格式填入。 3. 在UI界面中添加一个ItemSlot预制体,用来显示每个物品的图标和数量。 4. 在UI界面中添加一个拖拽组件,用来实现物品的拖拽和交换。 5. 在代码中调用Backpack组件的AddItem和RemoveItem方法,可以向背包中添加或移除物品。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值