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. 【vue iview】项目 win10 放在C盘 经常npm install不成功,就是因为 权限问题,把代码目录放到D盘就没事了。

    [vue iview]项目 win10 放在C盘 经常npm install不成功,就是因为 权限问题,把代码目录放到D盘就没事了.

  2. JavaScript -- DOM事件

    什么是事件 事件就是文档或浏览器窗口中发生的一些特定的交互瞬间.比如你在网页上见到的鼠标点击一个按钮,按钮的颜色发生了变化,就是因为这个标签绑定了点击事件 鼠标事件 onload:页面加载时触发 on ...

  3. GIT在团队中的最佳实践

    我们已经从SVN 切换到Git很多年了,现在几乎所有的项目都在使用Github管理, 本篇文章讲一下为什么使用Git, 以及如何在团队中正确使用. Git的优点 Git的优点很多,但是这里只列出我认为 ...

  4. Servlet的引入(即加入Servlet)

    今天讲的Servlet是根据上一章节<创建一个学生信息表,与页面分离>而结合. 一.看图分析 此模式有问题: 1.jsp需要呼叫javabean StudentService stuSer ...

  5. Java多线程 编写三各类Ticket、SaleWindow、TicketSaleCenter分别代表票信息、售票窗口、售票中心。 售票中心分配一定数量的票,由若干个售票窗口进行出售,利用你所学的线程知识来模拟此售票过程。

    package com.swift; import java.util.ArrayList; import java.util.HashMap; import java.util.List; impo ...

  6. (68)zabbix windows性能计数器使用详解

    概述 windows下的性能计数器让zabbix监控更加轻松,直接获取性能计数器的数值即可完成windows监控.性能计数器如下:   1 perf_counter["\Processor( ...

  7. python入门:while 循环的基本用法

    #!/usr/bin/env python # -*- coding:utf-8 -*- #while 循环的作用 import time while True: ") time.sleep ...

  8. destoon 自定义session丢失

    destoon 在使用session之前 应该实例化 $s​ession = new dsession(); destoon通过配置文件加载了不同session存储方式.如果你使用session的页面 ...

  9. Optimization & Map

  10. TB平台搭建之一

    最近在搭建公司的testbench,主要有一下总结: 1.TB主要有两部分:部分一,软件部分主要用C写的,她的作用是写硬件的驱动(其实就是让核的外围设备可以正常工作或工作到特定的环境上)甚至有可能写整 ...