CodeForces 651B Beautiful Paintings 贪心
1 second
256 megabytes
standard input
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.
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 the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
3 5
6
4 4
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 贪心的更多相关文章
- codeforces 651B Beautiful Paintings
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces 651B Beautiful Paintings【贪心】
题意: 给定序列,重新排序,使严格上升的子序列最多.求这些子序列总长度. 分析: 贪心,统计每个元素出现次数,每次从剩余的小的开始抽到大的,直到不再剩余元素. 代码: #include<iost ...
- codeforce 651B Beautiful Paintings
题意:后一个比前一个大就加一,问最大次数. #include<cstdio> #include<cstring> #include<algorithm> #incl ...
- [刷题codeforces]651B/651A
651B Beautiful Paintings 651A Joysticks 点击可查看原题 651B是一个排序题,只不过多了一步去重然后记录个数.每次筛一层,直到全为0.从这个题里学到一个正确姿势 ...
- codeforces 651B B. Beautiful Paintings
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 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 ...
- Codeforces Round #345 (Div. 2) B. Beautiful Paintings 暴力
B. Beautiful Paintings 题目连接: http://www.codeforces.com/contest/651/problem/B Description There are n ...
- Codeforces 651 B. Beautiful Paintings
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input stan ...
- codeforces 704B - Ant Man 贪心
codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...
随机推荐
- 线性表基本维护[ACM]
#include "iostream" #include "string" using namespace std; typedef struct node{ ...
- struts不同session范围添加、访问属性
第01步:编写bean类 package com.self.bean; import java.util.Date; public class User { private Date birthday ...
- 去掉vim的高亮的方法
使用vim时经常因为误用了组合键而进行了搜索操作,搜索到的内容会被加上背景色,而且背景色一直保持着,就算下一次打开这个文件,还会显示搜索到内容的背景色 在vim中使用一个命令即可去掉: nohl
- html5,表格
<table border="1"><caption>表格的实例</caption><tr><td>单元格</td ...
- yii2复选框
Yii2复选框的具体使用方法如下,以商品中的品牌为例在页面显示 第一种方法:使用ActiveForm::checkBoxlist()(这种方法可以把后台获取到的数据都生成复选框),具体使用如下: &l ...
- React笔记_(2)_react语法1
这一节内容主要以了解为主. 渐渐的体会react的语法和其特性. ① htmlAndJs 混合编写 react和以往的前后台书写方式不一样. 在之前的多个语言中,讲求的是将页面代码和js代码逻辑分开, ...
- kmemleak的使用---内存泄露检测工具【转】
转自:http://blog.csdn.net/lishenglong666/article/details/8287783 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] ...
- jqGrid中选择的行的数据[转]
如何获取jqGrid中选择的行的数据? 下面可以获取选择一行的id,如果你选择多行,那下面的id是最后选择的行的id: var id=$(‘#gridTable’).jqGrid(‘getGridPa ...
- 自定义Exception
本文改编自http://blog.csdn.net/stellaah/article/details/6738424 [总结] 1.自定义异常: class 异常类名 extends Exceptio ...
- Nagios监控Oralce
一.本文说明: 本文是监控本地的Oracle,其实监控远端的Oracle也是跟下面的步骤差不多的. 二.安装Nagios.Nagios插件.NRPE软件: 安装步骤可以参考<Linux下Nagi ...