A. Joysticks
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
input
3 5
output
6
input
4 4
output
5
Note

In the first sample game lasts for 6 minute by using the following algorithm:

  • at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%;
  • continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%;
  • at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%;
  • continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%;
  • at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%;
  • at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%.

After that the first joystick is completely discharged and the game is stopped.

做的第一道CF的题目自我鼓励一下- -|||(做了蛮久,没经验),题意:有个蛋疼的人有

俩游戏机,两者同时有电才能一直玩,但是充电头就一个,每分钟可以续(手动滑

稽)1%,另外一个不能充会掉电2%,求最大可玩时间。刚开始看出来这是道模拟题,

思路正确,就是while里的东西改了很久,规律:每次都找电最多的去玩,玩到再过一分

分钟就不能玩了,换另一个,这个拿去充电。循环不停,直到任意一个掉电2%关机为

止。这题有坑点,要是刚开始就不能玩或者只能玩一分钟,直接特盘掉,难怪我TEST7

显示超时....刚开始用a与b来模拟俩机器,发现不好使,还是数组好使。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
int list[2];
int main (void)
{
int a,b;
int cnt;
int index;
while (cin>>list[0]>>list[1])
{
if((list[0]==1&&list[1]==2)||(list[0]==2&&list[1]==1)||(list[1]==2&&list[0]==2))//玩一分钟特判
{
cout<<1<<endl;
continue;
}
else if(list[0]==1&&list[1]==1)//不能玩特判
{
cout<<0<<endl;
continue;
}
if(list[0]>=list[1])
swap(list[0],list[1]);//方便使用
cnt=0;
index=1;
while (list[0]>0&&list[1]>0)
{
while (list[index]>2)
{
list[index]-=2;
list[index==1?0:1]++;
cnt++;
}
index=(index==1)?0:1;//这个完了换另一个
if((list[0]==1&&list[1]==2)||(list[0]==2&&list[1]==1)||(list[0]==2&&list[1]==2))//循环内判断
{
cnt++;
break;
}
}
cout<<cnt<<endl;
}
return 0;
}

Codeforces Round #345 (Div. 2)——A. Joysticks(模拟+特判)的更多相关文章

  1. Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】

    A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  2. Codeforces Round #345 (Div. 2) A. Joysticks dp

    A. Joysticks 题目连接: http://www.codeforces.com/contest/651/problem/A Description Friends are going to ...

  3. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  4. Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)

    A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  5. Codeforces Round #543 (Div. 2) D 双指针 + 模拟

    https://codeforces.com/contest/1121/problem/D 题意 给你一个m(<=5e5)个数的序列,选择删除某些数,使得剩下的数按每组k个数以此分成n组(n*k ...

  6. Codeforces Round #398 (Div. 2) A. Snacktower 模拟

    A. Snacktower 题目连接: http://codeforces.com/contest/767/problem/A Description According to an old lege ...

  7. Codeforces Round #345 (Div. 2) D. Image Preview 暴力 二分

    D. Image Preview 题目连接: http://www.codeforces.com/contest/651/problem/D Description Vasya's telephone ...

  8. Codeforces Round #345 (Div. 2)

    DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...

  9. Codeforces Round #237 (Div. 2) B题模拟题

    链接:http://codeforces.com/contest/404/problem/B B. Marathon time limit per test 1 second memory limit ...

随机推荐

  1. ABAP的Package interface, 安卓的manifest.xml和Kubernetes的Capabilities

    ABAP 事务码SE21创建ABAP包接口.这是ABAP基于包层面的访问控制实现逻辑.包里可以存储很多ABAP对象.如果开发人员想将某些对象声明为包外程序也能访问,可以将这些对象放在包接口的Visib ...

  2. 卓越管理的实践技巧(2)成功的委派任务 Setup for Successful Delegation

    Setup for Successful Delegation 前文卓越管理的秘密(Behind Closed Doors)最后一部分提到了总结的13条卓越管理的实践技巧并列出了所有实践技巧名称的索引 ...

  3. Codeforces Round #321 (Div. 2) D Kefa and Dishes(dp)

    用spfa,和dp是一样的.转移只和最后一个吃的dish和吃了哪些有关. 把松弛改成变长.因为是DAG,所以一定没环.操作最多有84934656,514ms跑过,实际远远没这么多. 脑补过一下费用流, ...

  4. HTML之基本语法(段落标签、标题标签、空格标签、换行标签、图片标签和图片的基本属性)

    一.HTML标签 所谓的HTML的标签就是发明者认为定义好的一些单词,就相当于我们汉语中的字 二.HTML的语法 语法就是用来定义这些“字”应该如何解析或者书写的规则 三.常见标签及基本语法 1.人为 ...

  5. 苹果市值破万亿,iPhone 会涨价吗?

    今日导读 苹果教父乔布斯曾经说过:“活着就是为了改变世界.”虽然他在 56 岁时就遗憾离世,但他极具创新和变革的精神早已深埋进苹果公司的企业文化里,影响着一代又一代的人.就在最近,这家一直努力“改变世 ...

  6. 《毛毛虫团队》第七次作业:团队项目设计完善&编码

    一:实验名称:团队项目设计完善&编码 二:实验目的与要求 掌握软件编码实现的工程要求. 三:实验步骤 任务一:团队软件项目设计完善: 任务二:团队软件项目编码实现: 任务三:在团队博客发布博文 ...

  7. java基础—流

    一.JAVA流式输入/输出原理

  8. iOS中的数据存储方式_SQLite3

    优点: 1) SQLite是一款轻型的嵌入式数据库; 2) 它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了 3) 它的处理速度比Mysql.PostgreSQL这两款著名的数据库都还 ...

  9. c++ 用指针操作数组

    #include <iostream> using namespace std; const int Max = 5; double * fill_array(double * first ...

  10. vc文件操作汇总—支持wince

    一.判断文件及文件夹是否存在 // 判断文件是否存在 BOOL IsFileExist(const CString& csFile) { DWORD dwAttrib = GetFileAtt ...