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) ...
随机推荐
- Android使用ZXing生成带图片的二维码
效果图如下: 制作过程很简单的就是在原始的二维码图片上添加一个logn图标,代码的注释写得很详细,也就不给大家啰嗦了 package com.example.day44_02_qrcodewithlo ...
- java文件下载 rest
/** * 返回文件二进制 * */ @GET @Path("/excel") @Produces("application/vnd.ms-excel; charset= ...
- 【ruby】安装Ruby
系统需求 首先确定操作系统环境,不建议在 Windows 上面搞,所以你需要用: Mac OS X 任意 Linux 发行版本 配置系统包 $ sudo apt-get install -y buil ...
- 【crunch bang】字体美化
中文字体美化是个很讨厌的事情,无数初学者在这里面浪费了无数时间,做了无数没有意义的事情.但这也是不得不做的,我把 Debian/Ubuntu 所需要的中文字体美化操作步骤详细记录在这里,希望能节约大家 ...
- Linode 优惠码
Linode 是最好的vps $10的优惠码 Linode10,推荐码:bc7852453e280eee5a8ef045c5ab54ca091c8021 链接https://www.linode.co ...
- 视频处理控件TVideoGrabber如何对屏幕进行录制/压缩
TVideoGrabber可以对屏幕进行录制和压缩,本文来详细的说明在多种情况下TVideoGrabber是如何实现屏幕的录制和压缩. 屏幕录制 当VideoSource = vs_ScreenRec ...
- 人工智能深度学习Caffe框架介绍,优秀的深度学习架构
人工智能深度学习Caffe框架介绍,优秀的深度学习架构 在深度学习领域,Caffe框架是人们无法绕过的一座山.这不仅是因为它无论在结构.性能上,还是在代码质量上,都称得上一款十分出色的开源框架.更重要 ...
- Java中的排序算法(2)
Java中的排序算法(2) * 快速排序 * 快速排序使用分治法(Divide and conquer)策略来把一个序列(list)分为两个子序列(sub-lists). * 步骤为: * 1. 从数 ...
- JavaScript中统计Textarea字数并提示还能输入的字符
<span style="font-size:18px;"><script language="javascript"> functio ...
- PHP序列化以及反序列化系列[1]--PHP序列化格式的写法
反序列化:对单一的已序列化的变量进行操作,将其转换回 PHP 的值(zval). PHP序列化方式 PHP在序列化的时候会将相应的变量以对应的键值进行储存. 将一个类序列化的话,处理代码主要的 文件: ...