zoukankan      html  css  js  c++  java
  • CodeForces 651A(水题)

    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

    Input
    3 5
    Output
    6
    Input
    4 4
    Output
    5

    题意 两个游戏机,每分钟充电电量加1,不充电量减2,只能给一台游戏机充电(可交换),当其中一台电量为0则停在,求持续的分钟数
     1 #include<iostream>
     2 #include<cstdio>
     3 using namespace std;
     4 int main()
     5 {
     6     int a1,a2;
     7     while(cin>>a1>>a2)
     8     {
     9         if(a1<a2)
    10         {
    11             a2=a1+a2;
    12             a1=a2-a1;
    13             a2=a2-a1;
    14         }
    15         if(a1==1&&a2==1)
    16             cout<<0<<endl;
    17         int t=0;
    18         while(a1>0&&a2>0)
    19         {
    20             if(a2>a1)
    21             {
    22                 a2=a2-2;
    23                 a1=a1+1;
    24             }
    25             else
    26             {
    27                 a1=a1-2;
    28                 a2=a2+1;
    29             }
    30             t++;
    31         }
    32         cout<<t<<endl;
    33     }
    34     return 0;
    35 }
  • 相关阅读:
    poj1014 Dividing (多重背包)
    HDOJ 1316 How Many Fibs?
    最大字串和
    WHY IE AGAIN?
    Codeforces Round #143 (Div. 2) (ABCD 思维场)
    自用组帧工具
    菜鸟学EJB(二)——在同一个SessionBean中使用@Remote和@Local
    shell 块注释
    检测到在集成的托管管道模式下不适用的 ASP.NET 设置的解决方法
    Windows Myeclipse 10 安装 Perl 插件
  • 原文地址:https://www.cnblogs.com/Aa1039510121/p/5687890.html
Copyright © 2011-2022 走看看