CodeForces 651 A Joysticks

探讨两个充电状态不同的游戏控制器如何通过合理充电策略延长游戏时间,直到其中一个控制器完全耗尽电量。输入包括两个控制器的初始电量百分比,输出为游戏能持续的最大分钟数。
A. Joysticks
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1 percent and second one is charged at a2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).

Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.

Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.

Input

The first line of the input contains two positive integers a1 and a2 (1 ≤ a1, a2 ≤ 100), the initial charge level of first and second joystick respectively.

Output

Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.

Examples
input
3 5
output
6
input
4 4
output

5


#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;
long long int dp[205][205];
int n,m;
long long int dfs(int x,int y)
{
    //cout<<x<<" "<<y<<endl;
    if(dp[x][y]!=-1)
        return dp[x][y];
    if(x-2<0&&y-2>=0)
       dp[x][y]=dfs(x+1,y-2)+1;
    else if(x-2>=0&&y-2<0)
       dp[x][y]=dfs(x-2,y+1)+1;
    else
    {
       dp[x][y]=max(dfs(x+1,y-2),dfs(x-2,y+1));
       dp[x][y]++;
    }

    return dp[x][y];
}
int main()
{
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=100;i++)
        dp[i][0]=0,dp[0][i]=0;
    dp[1][1]=0;
    scanf("%d%d",&n,&m);
    printf("%lld\n",dfs(n,m));
    return 0;
}


转载于:https://www.cnblogs.com/dacc123/p/8228737.html

【最优潮流】直流最优潮流(OPF)课设(Matlab代码实现)内容概要:本文档主要围绕“直流最优潮流(OPF)课设”的Matlab代码实现展开,属于电力系统优化领域的教学与科研实践内容。文档介绍了通过Matlab进行电力系统最优潮流计算的基本原理与编程实现方法,重点聚焦于直流最优潮流模型的构建与求解过程,适用于课程设计或科研入门实践。文中提及使用YALMIP等优化工具包进行建模,并提供了相关资源下载链接,便于读者复现与学习。此外,文档还列举了大量与电力系统、智能优化算法、机器学习、路径规划等相关的Matlab仿真案例,体现出其服务于科研仿真辅导的综合性平台性质。; 适合人群:电气工程、自动化、电力系统及相关专业的本科生、研究生,以及从事电力系统优化、智能算法应用研究的科研人员。; 使用场景及目标:①掌握直流最优潮流的基本原理与Matlab实现方法;②完成课程设计或科研项目中的电力系统优化任务;③借助提供的丰富案例资源,拓展在智能优化、状态估计、微电网调度等方向的研究思路与技术手段。; 阅读建议:建议读者结合文档中提供的网盘资源,下载完整代码与工具包,边学习理论边动手实践。重点关注YALMIP工具的使用方法,并通过复现文中提到的多个案例,加深对电力系统优化问题建模与求解的理解。
### 关于 Codeforces Problem 1804A 的解决方案 Codeforces 是一个广受欢迎的在线编程竞赛平台,其中问题 1804A 可能涉及特定算法或数据结构的应用。尽管未提供具体题目描述,但通常可以通过分析输入输出样例以及常见解法来推导其核心逻辑。 #### 题目概述 假设该问题是关于字符串处理、数组操作或其他基础算法领域的内容,则可以采用以下方法解决[^2]: 对于某些初学者来说,遇到不熟悉的语言(如 Fortran),可能会感到困惑。然而,在现代竞赛环境中,大多数情况下会使用更常见的语言(C++、Python 或 Java)。因此,如果题目提及某种神秘的语言,可能只是为了增加趣味性而非实际需求。 #### 解决方案思路 以下是基于一般情况下的潜在解答方式之一: ```cpp #include <bits/stdc++.h> using namespace std; int main(){ int t; cin >> t; // 输入测试用例数量 while(t--){ string s; cin >> s; // 获取每组测试数据 // 假设这里需要执行一些简单的变换或者判断条件... bool flag = true; // 初始化标志位为真 for(char c : s){ if(c != 'a' && c != 'b'){ flag = false; break; } } cout << (flag ? "YES" : "NO") << "\n"; // 输出结果 } return 0; } ``` 上述代码片段展示了一个基本框架,适用于许多入门级字符串验证类问题。当然,这仅作为示范用途;真实场景下需依据具体要求调整实现细节。 #### 进一步探讨方向 除了官方题解外,社区论坛也是获取灵感的好地方。通过阅读他人分享的经验教训,能够加深对该类型习题的理解程度。同时注意积累常用技巧并灵活运用到不同场合之中[^1]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值