zoukankan      html  css  js  c++  java
  • 2018 ACM-ICPC 亚洲青岛区域网络赛 A 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 A​1​​,A​2​​,...,A​n​​ (A​i​​∈ {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 A​i​​=A​i+1​​=A​i+2​​=...=A​i+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≤10​3​​, 0≤m≤10​3​​, m≤n), indicating the sequence length and the number of PERFECTs DreamGrid gets.

    Output

    For each test case output one line containing two integers s​max​​ and s​min​​, 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.

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    
    int main()
    {
    	int T;
    	cin>>T;
    	while(T--)
    	{
    		int n,m;
    		cin>>n>>m;
    		if(n==m)
    		   cout<<m<<" "<<m<<endl;
    		else if(m==0)
    		   cout<<"0"<<" "<<"0"<<endl;
    		else 
    		{
    			if(n/m>=2)
                  cout<<m<<" "<<"1"<<endl;
                else 
                {
                	int c = n-m;
                	int s;
                	if(m%(c+1)==0)
                	   s = m/(c+1);
                	else 
                	   s = m/(c+1) + 1;
                	cout<<m<<" "<<s<<endl;
                }
    		}
    	}
    	return 0;
    } 
    
  • 相关阅读:
    HDU4507 吉哥系列故事――恨7不成妻(数位dp)
    UCF Local Programming Contest 2017 G题(dp)
    ICPC Latin American Regional Contests 2019 I题
    UCF Local Programming Contest 2017 H题(区间dp)
    HDU2089 不要62
    AcWing1084 数字游戏II(数位dp)
    UCF Local Programming Contest 2017 F题(最短路)
    Google Code Jam 2019 Round 1A Pylons(爆搜+贪心)
    AcWing1083 Windy数(数位dp)
    Vue
  • 原文地址:https://www.cnblogs.com/Romantic-Chopin/p/12451415.html
Copyright © 2011-2022 走看看