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

题意:在一个序列中,当遇到递增的数时,会觉得开心,现在给一组数,问可以开心几次
题解:先将序列从小到大排序,记录所有重复出现的数的次数,去掉出现次数最多的求剩下的数的和即可

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int n,a[],b[];
bool cmp(int x,int y)
{
return x>y;
}
int main()
{
int i,j,ans;
while(scanf("%d",&n)!=EOF)
{
ans=;
memset(b,,sizeof(b));
for(i=;i<n;i++)
{
scanf("%d",&a[i]);
b[a[i]]++;
}
sort(b,b+,cmp);
for(i=;i<;i++)
ans+=b[i];
printf("%d\n",ans);
}
return ;
}

CodeForces 651B Beautiful Paintings 贪心的更多相关文章

  1. codeforces 651B Beautiful Paintings

    B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...

  2. Codeforces 651B Beautiful Paintings【贪心】

    题意: 给定序列,重新排序,使严格上升的子序列最多.求这些子序列总长度. 分析: 贪心,统计每个元素出现次数,每次从剩余的小的开始抽到大的,直到不再剩余元素. 代码: #include<iost ...

  3. codeforce 651B Beautiful Paintings

    题意:后一个比前一个大就加一,问最大次数. #include<cstdio> #include<cstring> #include<algorithm> #incl ...

  4. [刷题codeforces]651B/651A

    651B Beautiful Paintings 651A Joysticks 点击可查看原题 651B是一个排序题,只不过多了一步去重然后记录个数.每次筛一层,直到全为0.从这个题里学到一个正确姿势 ...

  5. codeforces 651B B. Beautiful Paintings

    B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...

  6. Codeforces Round #345 (Div. 2)——B. Beautiful Paintings(贪心求上升序列个数)

    B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...

  7. Codeforces Round #345 (Div. 2) B. Beautiful Paintings 暴力

    B. Beautiful Paintings 题目连接: http://www.codeforces.com/contest/651/problem/B Description There are n ...

  8. Codeforces 651 B. Beautiful Paintings

    B. Beautiful Paintings   time limit per test 1 second memory limit per test 256 megabytes input stan ...

  9. codeforces 704B - Ant Man 贪心

    codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...

随机推荐

  1. oracle中的常用函数

    一.运算符算术运算符:+ - * / 可以在select 语句中使用连接运算符:|| select deptno|| dname from dept; 比较运算符:> >= = != &l ...

  2. OpenStack 计算节点关机,虚拟机状态解决办法

    检查服务正常化 1 nova-manage service list 发现很多nova服务没有启动. 全部启动,直到nova-manage service list所有服务都是:)而不是XXX. 虚拟 ...

  3. an'gularjs 环境搭建之NodeJS、NPM安装配置步骤(windows版本)

    NodeJS.NPM安装配置步骤(windows版本)  :http://xiaoyaojones.blog.163.com/blog/static/28370125201351501113581/ ...

  4. 天气预报接口api(中国天气网)

    中国天气weather.comhttp://m.weather.com.cn/data/101110101.html(六天预报) http://www.weather.com.cn/data/sk/1 ...

  5. PHPCMS V9 环境搭建

    PHPCMS V9的学习总结分为以下几点: [1]PHPCMS 简介 PHP原始为Personal Home Page的缩写,(外文名:PHP: Hypertext Preprocessor,中文名: ...

  6. android 学习随笔十七(服务 )

    1.Service 四大组件之一 运行于后台,没有前台界面的组件,用于运行需要在后台运行的代码 可以理解为没有前台的Activity 定义方式:创建java类继承Service,清单文件中注册该类 p ...

  7. linux设备驱动归纳总结(三):5.阻塞型IO实现【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-60025.html linux设备驱动归纳总结(三):5.阻塞型IO实现 xxxxxxxxxxxxxx ...

  8. javaWeb 使用cookie显示上次访问网站时间

    package de.bvb.cookie; import java.io.IOException; import java.io.PrintWriter; import java.util.Date ...

  9. NFine - 全球领先的快速开发平台 Dapper Chloe

    http://www.nfine.cn/ 技术交流群:549652099 出处:http://www.cnblogs.com/huanglin/ 分享一个轻型ORM--Dapper选用理由 Chloe

  10. test if DEMO

    可参考:http://blog.chinaunix.net/uid-20671208-id-3643362.html 1.test 举例: test -d ~/auto && echo ...