Live Love(思维)
DreamGrid is playing the music game Live Love. He has just finished a song consisting of n notes and got a result sequence A1,A2,...,An (Ai∈ {PERFECT, NON-PERFECT}). The score of the song is equal to the max-combo of the result sequence, which is defined as the maximum number of continuous PERFECTs in the sequence.
Formally speaking, max-combo(A)=max { k | k is an integer and there exists an integer i (1≤i≤n−k+1) such that Ai=Ai+1=Ai+2=...=Ai+k−1= PERFECT }. For completeness, we define max(∅)=0.
As DreamGrid is forgetful, he forgets the result sequence immediately after finishing the song. All he knows is the sequence length n and the total number of PERFECTs in the sequence, indicated by m. Any possible score s he may get must satisfy that there exists a sequence A′ of length n containing exactly m PERFECTs and (n−m) NON-PERFECTs and max-combo(A′)=s. Now he needs your help to find the maximum and minimum s among all possible scores.
Input
There are multiple test cases. The first line of the input contains an integer T (1≤T≤100), indicating the number of test cases. For each test case:
The only line contains two integers n and m (1≤n≤103, 0≤m≤103, m≤n), indicating the sequence length and the number of PERFECTs DreamGrid gets.
Output
For each test case output one line containing two integers smax and smin, indicating the maximum and minimum possible score.
Sample Input
5
5 4
100 50
252 52
3 0
10 10
Sample Output
4 2
50 1
52 1
0 0
10 10
Hint
Let's indicate a PERFECT as P and a NON-PERFECT as N.
For the first sample test case, the sequence (P,P,P,P,N) leads to the maximum score and the sequence (P,P,N,P,P) leads to the minimum score.
题目意思:对于t组样例,每一组一共有n个音符,m个音符属于一种,剩下的音符都是不同种的,出现连续同一种音符的个数作为得分,求最大得分和最小得分。
解题思路:其实我们可以这样想一共会有x=n-m+1种音符,最大得分必然是相同音符的数量也就是m,而对于最小得分:如果音符的种类x大于等于同一种的数量m,
那么同一种音符便可以被不同种的音符一一分割开;如果音符的种类小于同一种的数量m,那么想要得到最小连续同一类的音符数,可以理解为将m利用不同种类的音符划分为若干部分。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int t,a,b,ans,x;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&a,&b);
x=a-b+;
if(b==)
{
ans=;
}
else if(x>=b)
{
ans=;
}
else if(x<b)
{
if(b%x!=)
{
ans=b/x+;
}
else
{
ans=b/x;
}
}
printf("%d %d\n",b,ans);
}
return ;
}
Live Love(思维)的更多相关文章
- [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序
用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html 目录 马桶排序(令人 ...
- Photoshop、Illustrator思维导图笔记
半年前学习Photoshop时记得的思维导图笔记,可能不是很全,常用的基本都记下了.
- CYQ.Data 从入门到放弃ORM系列:开篇:自动化框架编程思维
前言: 随着CYQ.Data 开始回归免费使用之后,发现用户的情绪越来越激动,为了保持这持续的激动性,让我有了开源的念头. 同时,由于框架经过这5-6年来的不断演进,以前发的早期教程已经太落后了,包括 ...
- 计算机程序的思维逻辑 (8) - char的真正含义
看似简单的char 通过前两节,我们应该对字符和文本的编码和乱码有了一个清晰的认识,但前两节都是与编程语言无关的,我们还是不知道怎么在程序中处理字符和文本. 本节讨论在Java中进行字符处理的基础 - ...
- 计算机程序的思维逻辑 (29) - 剖析String
上节介绍了单个字符的封装类Character,本节介绍字符串类.字符串操作大概是计算机程序中最常见的操作了,Java中表示字符串的类是String,本节就来详细介绍String. 字符串的基本使用是比 ...
- 计算机程序的思维逻辑 (31) - 剖析Arrays
数组是存储多个同类型元素的基本数据结构,数组中的元素在内存连续存放,可以通过数组下标直接定位任意元素,相比我们在后续章节介绍的其他容器,效率非常高. 数组操作是计算机程序中的常见基本操作,Java中有 ...
- 计算机程序的思维逻辑 (33) - Joda-Time
Joda-Time上节介绍了JDK API中的日期和时间类,我们提到了JDK API的一些不足,并提到,实践中有一个广泛使用的日期和时间类库,Joda-Time,本节我们就来介绍Joda-Time.俗 ...
- 计算机程序的思维逻辑 (53) - 剖析Collections - 算法
之前几节介绍了各种具体容器类和抽象容器类,上节我们提到,Java中有一个类Collections,提供了很多针对容器接口的通用功能,这些功能都是以静态方法的方式提供的. 都有哪些功能呢?大概可以分为两 ...
- 成吨提高开发效率:Intellij Shortcuts精简子集与思维模式
在线精简cheatsheet备查表:intellij.linesh.twGithub项目:intellij-mac-frequent-keymap Intellij的快捷键多而繁杂,从官方推荐的key ...
- "Becoming Functional" 阅读笔记+思维导图
<Becoming Functional>是O'Reilly公司今年(2014)7月发布的一本薄薄的小册子,151页,介绍了函数式编程的基本概念.全书使用代码范例都是基于JVM的编程语言, ...
随机推荐
- crashes
iOS 僵尸对象调试 - 简书 iOS APP审核被拒的解决之道(2.1) - - ITeye博客 iOS应用崩溃日志分析 - CocoaChina 苹果开发中文站 - 最热的iPhone开发社区 最 ...
- python里的默认参数
def extendList(val, test=[]): test.append(val) return test list1 = extendList(10) list2 = extendList ...
- 记录一下idea的破解方法
刚把idea升级到最新版,发现要重新激活,网上查了有改host的方法可行,只是有点麻烦.无意中发现一个方法,如图所示 输入 http://idea.java.sx/ 即可,亲测可用.如果资金 ...
- 【oracle的安装和基本配置】
/*----------------------------登录和安装--------------------------------------*/ #从官网上选择安装的版本,任何一个版本都可以,目 ...
- jqu
1 /*2 * 说明:3 * 本源代码的中文注释乃Auscarlin呕心沥血所作.旨在促进jQuery的传播以及向广大jQuery爱好者提供一个进阶4 *的途径,以让各位更加深入地了解jQuery,学 ...
- 百度地图热力图--批量地址转换应用(基于百度api)
需求:把外卖订餐地址做个用户分布热力图 思路分析:第一步去百度地图api开放平台找例子 http://lbsyun.baidu.com/jsdemo.htm#c1_15 首先从百度API的demo例子 ...
- Python面向对象总结及类与正则表达式
Python3 面向对象 一丶面向对象技术简介 类(Class): 用来描述具有相同的属性和方法的对象的集合.它定义了该集合中每个对象所共有的属性和方法.对象是类的实例. 方法:类中定义的函数. 类变 ...
- 使用docker-compose运行微服务项目#eureka+config+auth+gateway+module
微服务架构中我们使用了必须的四个组件,eureka config gateway auth 其中config依赖eureka,auth依赖前两者,gateway又依赖auth 这样就确定了四个组件的启 ...
- 20155321 2016-2017-2《Java程序设计》课堂实践项目2
20155321 2016-2017-2<Java程序设计>课堂实践项目2 实践内容 编写MyCP.java 实现类似Linux下cp XXX1 XXX2的功能,要求MyCP支持两个参数: ...
- css首行缩进2个字符
css设置: p{ text-indent:2em; }