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的编程语言, ...
随机推荐
- Linux基础-4.正文处理命令及tar命令
1.使用cat命令进行文件的纵向合并 1)掌握使用cat命令的纵向合并 a)例如:使用cat命令将test1.file1.txt和file2这三个文件纵向合并为file文件的命令为: cat test ...
- SQL逻辑查询处理的步骤序号
(8)SELECT (9) DISTINCT <select_list> (1)FROM <left_table> (3)<join_type>JOIN<ri ...
- Python 爬虫 多进程清洗代理
利用多线程检测代理网站提供的免费代理是否可用 import requests from lxml import etree import time import multiprocessing def ...
- x01.os.24: 来点代码
<Orange'S 一个操作系统的实现>源代码 <Linux 0.11 内核完全注释>源代码 linux-0.12 源代码: 解决了 Not Owner 问题 闲来无事,在 ...
- A1037
给两个序列,一一对应相乘,求最大和. 0不算数,输入时按正负共分为4个数组. #include<cstdio> #include<algorithm> #include< ...
- DataTable 递归 简单的程序,来实现无限级列表 结合 jquery.table.js 实现
protected void DiGuiDataTable(DataTable FromDataTable, DataTable ToDataTable, object pid) { ) { fore ...
- .NET Core中使用RabbitMQ正确方式
.NET Core中使用RabbitMQ正确方式 首先甩官网:http://www.rabbitmq.com/ 然后是.NET Client链接:http://www.rabbitmq.com/dot ...
- 写一个 setter 方法用于完成 @property (nonatomic, retain) NSString *name,
写一个 setter 方法用于完成 @property (nonatomic, retain) NSString *name 写一个 setter 方法用于完成 @property (nonatomi ...
- Ajax文件上传三式
文件上传(三式) 1.urls.py文件 url(r'^upload.html$', views.upload), 2.views.py文件 import os def upload(request) ...
- Python中的矩阵操作
Numpy 通过观察Python的自有数据类型,我们可以发现Python原生并不提供多维数组的操作,那么为了处理矩阵,就需要使用第三方提供的相关的包. NumPy 是一个非常优秀的提供矩阵操作的包.N ...