Rewards - #256 (Div. 2) A (448A)水题

本文探讨了如何合理分配奖杯和奖牌到多个货架上,确保每个货架不同时存放奖杯和奖牌,且限制奖杯不超过5个,奖牌不超过10个。通过实例分析,提供了解决方案。

A. Rewards
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Bizon the Champion is called the Champion for a reason.

Bizon the Champion has recently got a present — a new glass cupboard with n shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has a1 first prize cups, a2 second prize cups and a3third prize cups. Besides, he has b1 first prize medals, b2 second prize medals and b3 third prize medals.

Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules:

  • any shelf cannot contain both cups and medals at the same time;
  • no shelf can contain more than five cups;
  • no shelf can have more than ten medals.

Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.

Input

The first line contains integers a1a2 and a3 (0 ≤ a1, a2, a3 ≤ 100). The second line contains integers b1b2 and b3 (0 ≤ b1, b2, b3 ≤ 100). The third line contains integer n (1 ≤ n ≤ 100).

The numbers in the lines are separated by single spaces.

Output

Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).

Sample test(s)
input
1 1 1
1 1 1
4
output
YES
input
1 1 3
2 3 4
2
output
YES
input
1 0 0
1 0 0
1
output
NO

题意:上面三个是奖杯,下面三个是奖牌,一个橱子最多放5个奖杯或10个奖牌,问现有的橱子是否够用……………一开始理解成是否能把在把所有物品都放进橱子的情况下,使橱子填满……。

AC代码如下:

#include<cstdio>
#include<cstring>
using namespace std;
int main()
{ int n,m,i,j,k,num1=0,num2=0,mi=0;
  for(i=1;i<=3;i++)
  { scanf("%d",&k);
    num1+=k;
  }
  for(i=1;i<=3;i++)
  { scanf("%d",&k);
    num2+=k;
  }
  mi=num1/5+num2/10;
  num1%=5;
  num2%=10;
  if(num1)
   mi++;
  if(num2)
   mi++;
  scanf("%d",&n);
  if(mi<=n)
   printf("YES\n");
  else
   printf("NO\n");
}


<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>高三勇者大冒险:终极备考RPG指南</title> <style> /* 游戏风格基础设置 */ :root { --quest-blue: #4e73df; --epic-purple: #6f42c1; --rare-green: #1cc88a; --common-gray: #858796; --legendary-orange: #f6c23e; --health-red: #e74a3b; --mana-blue: #36b9cc; --stamina-yellow: #f6c23e; --dark-bg: #2a3042; --light-text: #f8f9fc; } @import url(&#39;https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Noto+Sans+SC:wght@400;700&display=swap&#39;); body { background-color: var(--dark-bg); color: var(--light-text); font-family: &#39;Noto Sans SC&#39;, sans-serif; line-height: 1.6; background-image: url(&#39;https://img.freepik.com/free-vector/pixel-art-game-background-nature-landscape_107791-740.jpg&#39;); background-size: cover; background-attachment: fixed; padding: 0; margin: 0; } .rpg-container { max-width: 1000px; margin: 0 auto; background-color: rgba(42, 48, 66, 0.9); border: 4px solid var(--epic-purple); border-radius: 10px; box-shadow: 0 0 30px rgba(110, 66, 193, 0.5); overflow: hidden; } /* 游戏标样式 */ .rpg-header { background: linear-gradient(135deg, var(--quest-blue), var(--epic-purple)); padding: 30px; text-align: center; position: relative; border-bottom: 5px solid var(--legendary-orange); } .rpg-title { font-family: &#39;Press Start 2P&#39;, cursive; font-size: 2.2rem; color: white; text-shadow: 3px 3px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000; margin-bottom: 15px; letter-spacing: 2px; } .rpg-subtitle { font-size: 1.2rem; color: rgba(255,255,255,0.8); font-weight: bold; } /* 角色状态栏 */ .character-status { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; padding: 15px; background-color: rgba(0,0,0,0.3); border-bottom: 2px solid var(--quest-blue); } .status-bar { display: flex; flex-direction: column; align-items: center; } .status-label { font-size: 0.8rem; color: var(--light-text); margin-bottom: 5px; } .status-value { font-weight: bold; font-size: 1.2rem; } .health { color: var(--health-red); } .mana { color: var(--mana-blue); } .stamina { color: var(--stamina-yellow); } .level { color: var(--rare-green); } /* 任务日志区域 */ .quest-log { padding: 20px; } .chapter-title { font-family: &#39;Press Start 2P&#39;, cursive; font-size: 1.2rem; color: var(--legendary-orange); margin: 30px 0 20px; padding-bottom: 10px; border-bottom: 2px dashed var(--epic-purple); text-shadow: 2px 2px 0 #000; } /* 任务卡片样式 */ .quest-card { background: linear-gradient(135deg, rgba(46, 52, 78, 0.8), rgba(32, 38, 58, 0.8)); border: 2px solid var(--quest-blue); border-radius: 8px; padding: 15px; margin-bottom: 20px; position: relative; box-shadow: 0 5px 15px rgba(0,0,0,0.3); transition: transform 0.3s; } .quest-card:hover { transform: translateY(-5px); border-color: var(--rare-green); } .quest-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; } .quest-name { font-weight: bold; font-size: 1.1rem; color: white; display: flex; align-items: center; } .quest-type { display: inline-block; padding: 3px 8px; border-radius: 4px; font-size: 0.7rem; font-weight: bold; margin-left: 10px; } .main-quest { background-color: var(--epic-purple); } .daily-quest { background-color: var(--quest-blue); } .skill-quest { background-color: var(--rare-green); } .event-quest { background-color: var(--legendary-orange); color: #000; } .quest-rewards { display: flex; } .reward { margin-left: 10px; font-size: 0.8rem; background-color: rgba(0,0,0,0.3); padding: 3px 8px; border-radius: 4px; border: 1px solid var(--common-gray); } .quest-description { margin: 10px 0; line-height: 1.5; } .quest-objectives { margin-top: 15px; } .objective { display: flex; align-items: center; margin-bottom: 8px; padding-left: 25px; position: relative; } .objective:before { content: "◻"; position: absolute; left: 5px; color: var(--common-gray); } .objective.completed:before { content: "✓"; color: var(--rare-green); } /* 技能树样式 */ .skill-tree { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 15px; margin-top: 20px; } .skill-card { background-color: rgba(32, 38, 58, 0.8); border: 2px solid var(--common-gray); border-radius: 8px; padding: 15px; transition: all 0.3s; } .skill-card:hover { border-color: var(--rare-green); box-shadow: 0 0 15px rgba(28, 200, 138, 0.3); } .skill-name { font-weight: bold; color: white; margin-bottom: 5px; display: flex; justify-content: space-between; } .skill-level { color: var(--legendary-orange); } .skill-description { font-size: 0.9rem; color: rgba(255,255,255,0.7); } .cooldown { margin-top: 10px; font-size: 0.8rem; color: var(--mana-blue); } /* 游戏底部区域 */ .rpg-footer { text-align: center; padding: 20px; background-color: rgba(0,0,0,0.5); border-top: 2px solid var(--epic-purple); } .save-button { background: linear-gradient(135deg, var(--rare-green), #17a673); color: white; border: none; padding: 12px 25px; font-size: 1.1rem; font-weight: bold; border-radius: 50px; cursor: pointer; box-shadow: 0 5px 15px rgba(28, 200, 138, 0.4); transition: all 0.3s; } .save-button:hover { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(28, 200, 138, 0.6); } /* 响应式设计 */ @media (max-width: 768px) { .character-status { grid-template-columns: repeat(2, 1fr); } .rpg-title { font-size: 1.5rem; } .skill-tree { grid-template-columns: 1fr; } } </style> </head> <body> <div class="rpg-container"> <div class="rpg-header"> <h1 class="rpg-title">高三勇者大冒险</h1> <p class="rpg-subtitle">终极备考RPG指南 · 2025届黄金版</p> </div> <div class="character-status"> <div class="status-bar"> <span class="status-label">生命值</span> <span class="status-value health">❤️ 85/100</span> </div> <div class="status-bar"> <span class="status-label">专注力</span> <span class="status-value mana">🔵 70/100</span> </div> <div class="status-bar"> <span class="status-label">耐力</span> <span class="status-value stamina">🟡 90/100</span> </div> <div class="status-bar"> <span class="status-label">等级</span> <span class="status-value level">⭐ Lv.5</span> </div> </div> <div class="quest-log"> <h2 class="chapter-title">第一章: 新手村准备</h2> <div class="quest-card"> <div class="quest-header"> <span class="quest-name">装备你的武器库 <span class="quest-type main-quest">主线任务</span> </span> <div class="quest-rewards"> <span class="reward">EXP +200</span> <span class="reward">金币 +500</span> </div> </div> <div class="quest-description"> 收集并整理你的学习装备:五科笔记本、错本、历年真集、彩色标记笔。记得定期维护你的装备! </div> <div class="quest-objectives"> <div class="objective completed">购买各科笔记本</div> <div class="objective completed">准备错本系统</div> <div class="objective">收集近5年真</div> <div class="objective">建立文具补给包</div> </div> </div> <h2 class="chapter-title">第二章: 每日修行</h2> <div class="quest-card"> <div class="quest-header"> <span class="quest-name">晨读的智慧 <span class="quest-type daily-quest">每日任务</span> </span> <div class="quest继续完成代码
05-31
def update(self, memory): # Convert memory to tensors old_states = torch.stack(memory.states).to(device).detach() # Convert states to tensor old_actions = torch.stack(memory.actions).to(device).detach() # Convert actions to tensor old_logprobs = torch.stack(memory.logprobs).to(device).detach() # Convert log probabilities to tensor # Monte Carlo rewards rewards = [] # Initialize rewards list discounted_reward = 0 # Initialize discounted reward for reward, is_terminal in zip(reversed(memory.rewards), reversed(memory.is_terminals)): if is_terminal: # If the state is terminal discounted_reward = 0 # Reset discounted reward discounted_reward = reward + (self.gamma * discounted_reward) # Compute discounted reward rewards.insert(0, discounted_reward) # Insert at the beginning of the list rewards = torch.tensor(rewards, dtype=torch.float32).to(device) # Convert rewards to tensor rewards = (rewards - rewards.mean()) / (rewards.std() + 1e-7) # Normalize rewards # Update for K epochs for _ in range(self.K_epochs): # Get action probabilities and state values action_probs, state_values = self.policy(old_states) # Get action probabilities and state values dist = Categorical(action_probs) # Create a categorical distribution new_logprobs = dist.log_prob(old_actions) # Compute new log probabilities of actions entropy = dist.entropy() # Compute entropy for exploration # Calculate ratios ratios = torch.exp(new_logprobs - old_logprobs.detach()) # Compute probability ratios # Advantages advantages = rewards - state_values.detach().squeeze() # Compute advantages # Surrogate loss surr1 = ratios * advantages # Surrogate loss 1 surr2 = torch.clamp(ratios, 1 - self.eps_clip, 1 + self.eps_clip) * advantages # Clipped loss loss_actor = -torch.min(surr1, surr2).mean() # Actor loss # Critic loss loss_critic = self.MseLoss(state_values.squeeze(), rewards) # Critic loss # Total loss loss = loss_actor + 0.5 * loss_critic - 0.01 * entropy.mean() # Combined loss # Update policy self.optimizer.zero_grad() # Zero the gradient buffers loss.backward() # Backpropagate loss self.optimizer.step() # Perform a parameter update # Update old policy self.policy_old.load_state_dict(self.policy.state_dict()) # Copy new policy parameters to old policy 详解一下这个方法
最新发布
09-06
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值