zoukankan      html  css  js  c++  java
  • CodeForces

    正式更换编译器为: VS Code

    如何配置环境:click here

    代码格式化工具:clang-format

    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

    题意

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

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

    可以超过100%

    题解

    一:DP

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

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

    // Author : RioTian
    // Time : 20/10/14
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int dp[320][320], 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() {
        // freopen("in.txt", "r", stdin);
        ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
        int a, b;
        cin >> a >> b;
        if (a == 1 && b == 1)
            cout << 0 << endl;
        else
            cout << solve(a, b) << endl;
    }
    

    二:数学

    // Author : RioTian
    // Time : 20/10/14
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int main() {
        // freopen("in.txt","r",stdin);
        ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
        int a, b; cin >> a >> b;
        cout << ((a + b == 2) ? 0 : a + b - 2 - !(a - b) % 3) << endl;
    }
    

    三:模拟

    // Author : RioTian
    // Time : 20/10/14
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int main() {
        // freopen("in.txt","r",stdin);
        ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
        int a, b, cnt = 0;
        cin >> a >> b;
        while (a > 0 && b > 0) {
            if (a < 2 && b < 2) break;
            if (a < b) swap(a, b);
            a -= 2, b++, cnt++;
        }
        cout << cnt << endl;
    }
    
  • 相关阅读:
    .NET Task揭秘(一)
    .net线程池内幕
    Branch 向量化
    让你的gdb print 更可读
    获取web项目的绝对路径的方法总结
    Android事件监听(一)——简介篇
    Android事件监听(二)——点击鼠标事件
    jsp运行环境的安装和配置
    log4j中的DailyRollingFileAppender日志输出器工作原理
    开发环境搭建
  • 原文地址:https://www.cnblogs.com/RioTian/p/13816067.html
Copyright © 2011-2022 走看看