zoukankan      html  css  js  c++  java
  • Codeforces Round #345 (Div. 2) A. Joysticks dp

    A. Joysticks

    题目连接:

    http://www.codeforces.com/contest/651/problem/A

    Description

    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.

    Sample Input

    3 5

    Sample Output

    6

    Hint

    题意

    你有两个手机,和一个充电器,如果手机插上充电器,每秒涨%1的电,如果不插充电器,每秒掉%2的电

    问你最多能维持多久两个手机都有电。

    可以超过100%

    题解:

    我写的是dp,dp[i][j]表示第一个手机有i的电,第二个手机有j的电最长能够坚持多久

    然后特判一下1 1的情况就好了。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    int a1,a2;
    int dp[320][320];
    int vis[320][320];
    int solve(int x,int y)
    {
        if(x>y)swap(x,y);
        if(x<=0)return 0;
        if(vis[x][y])return dp[x][y];
        vis[x][y]=1;
        dp[x][y]=max(solve(x-2,y+1),solve(x+1,y-2))+1;
        return dp[x][y];
    }
    int main()
    {
        cin>>a1>>a2;
        if(a1==1&&a2==1)return puts("0"),0;
        cout<<solve(a1,a2)<<endl;
    }
  • 相关阅读:
    《不生不熟》读后感 读书笔记
    《亚洲与一战》读后感 读书笔记
    《厨房》读后感 读书笔记
    《娇惯的心灵》读后感 读书笔记
    《实践理性批判》读后感 读书笔记
    嵌入式三级知识点整理
    C语言:输入一个数,输出比这个数小的所有素数,并求出个数。
    C语言知识点记录
    C语言-实现矩阵的转置-随机函数产生随机数并赋予数组中-190222
    将数字字符转为数字的两种方法。
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5253074.html
Copyright © 2011-2022 走看看