CodeForces 651A Joysticks

水题。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <stack>
using namespace std;
typedef long long LL;
const int maxn=1e5+9;
const int inf=1e9+9;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int a,b;
    while(~scanf("%d%d",&a,&b))
    {
        LL cnt=0;
        while(1)
        {
            if(a==0 || b==0)
                break;
            if(a==1 && b==1)
                break;
            if(a>b)
            {
                b++;
                a-=2;
            }
            else
            {
                a++;
                b-=2;
            }
            cnt++;
        }
        printf("%I64d\n",cnt);
    }
    return 0;
}
时间: 2024-08-11 05:45:50

CodeForces 651A Joysticks的相关文章

CodeForces 651A Joysticks 贪心

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

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 m

codeforces - 651A 题解

大概题意如下:有两个玩具,分别拥有a1的电量和a2的电量:两个玩具每分钟耗电量为2单位,如果有一个或两个的电量下降到1以下就停止游戏:我们还有一个充电器,每分钟只能给一个玩具净充电1单位:问游戏时间长度. 解法很简单,取贪心策略:每次充电给电量较低的玩具充电. 题目做不出来往往是踩了这个坑:如果两个玩具开局电量都是1,那么游戏时间将是0.注意这句话:" Hence, if at the beginning of minute some joystick is charged by 1 perce

[刷题codeforces]651B/651A

651B Beautiful Paintings 651A Joysticks 点击可查看原题 651B是一个排序题,只不过多了一步去重然后记录个数.每次筛一层,直到全为0.从这个题里学到一个正确姿势:给定一个排好序的的数组,怎么把它变成一个去重加权的新数组. 只需要一个while循环+一个指针. #define N 10 #include<iostream> using namespace std; int main() { int a[N]={2,2,3,5,7,7,7,8,11,11};

16.05.25-16.06.10 题集

继2016.05.24续: codeforces 651B. Beautiful Paintings-简单 http://codeforces.com/problemset/problem/651/B 大意:给出一个序列,求解其任意排列中满足ai?+?1?>?ai 的元素个数最大和. 分析:理想情况下,无重复元素的0从小到大的排列,满足条件的元素个数最多,是n-1. 非理想情况下还有重复元素,只要不断提取出重复的这些元素归到另一集合再这样讨论即可. #include <iostream>

A Joysticks (Codeforces Round 345 (Div 2) )

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 m

[2016-03-08][codeforces][651][A][Joysticks]

时间:2016-03-08 20:54:05 星期二 题目编号:CF 651 A 题目大意:给两个游戏操纵杆,每个操纵杆分别有a1,a2%的电量,充电器只有一个,每分钟每个操纵杆消耗2%(如果没有充电),增加1%(如果充电),问游戏最长能持续多少时间,充电点允许超过100%,电量为0,游戏结束 输入:a1 a2 输出:最长游戏时间 分析:给电量少的充电,直到有一个没电... #include <vector> #include <list> #include <map>

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

 cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....       其实这个应该是昨天就写完的,不过没时间了,就留到了今天.. 地址:http://codeforces.com/contest/651/problem/A A. Joysticks time limit per test 1 second memory limit per test 256

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多