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;
    }
    
  • 相关阅读:
    影响一个UIView是否能正常显示的几个因素
    浅谈多进程多线程的选择
    Spring阅读方法
    数据库范式通俗解释
    MySQL学习笔记(二):MySQL数据类型汇总及选择参考
    MySQL学习笔记(一):SQL基础
    存储过程优缺点
    MySQL学习笔记(三):常用函数
    bzoj 3576[Hnoi2014]江南乐 sg函数+分块预处理
    bzoj 3166 [Heoi2013]Alo 可持久化Trie
  • 原文地址:https://www.cnblogs.com/RioTian/p/13816067.html
Copyright © 2011-2022 走看看