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 }
  • 相关阅读:
    hdu6229 Wandering Robots 2017沈阳区域赛M题 思维加map
    hdu6223 Infinite Fraction Path 2017沈阳区域赛G题 bfs加剪枝(好题)
    hdu6438 Buy and Resell 买卖物品 ccpc网络赛 贪心
    hdu6441 Find Integer 求勾股数 费马大定理
    bzoj 1176 Mokia
    luogu 3415 祭坛
    bzoj 1010 玩具装箱
    bzoj 3312 No Change
    luogu 3383【模板】线性筛素数
    bzoj 1067 降雨量
  • 原文地址:https://www.cnblogs.com/Aa1039510121/p/5687890.html
Copyright © 2011-2022 走看看