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 (1ink+1) such that Ai​​=Ai+1​​=Ai+2​​=...=Ai+k1​​= 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 (nm) 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 (1T100), indicating the number of test cases. For each test case:

The only line contains two integers n and m (1n103​​, 0m103​​, mn), 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利用不同种类的音符划分为若干部分。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int main()
 6 {
 7     int t,a,b,ans,x;
 8     scanf("%d",&t);
 9     while(t--)
10     {
11         scanf("%d%d",&a,&b);
12         x=a-b+1;
13         if(b==0)
14         {
15             ans=0;
16         }
17         else if(x>=b)
18         {
19             ans=1;
20         }
21         else if(x<b)
22         {
23             if(b%x!=0)
24             {
25                 ans=b/x+1;
26             }
27             else
28             {
29                 ans=b/x;
30             }
31         }
32         printf("%d %d\n",b,ans);
33     }
34     return 0;
35 }

 

转载于:https://www.cnblogs.com/wkfvawl/p/9655906.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值