CF1839A.The Good Array

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given two integers nn and kk.

An array a1,a2,…,ana_1, a_2, \ldots, a_n of length nn, consisting of zeroes and ones is good if for all integers ii from 11 to nn both of the following conditions are satisfied:

  • at least ⌈ik⌉\lceil \frac{i}{k} \rceil of the first ii elements of aa are equal to 11,
  • at least ⌈ik⌉\lceil \frac{i}{k} \rceil of the last ii elements of aa are equal to 11.

Here, ⌈ik⌉\lceil \frac{i}{k} \rceil denotes the result of division of ii by kk, rounded up. For example, ⌈63⌉=2\lceil \frac{6}{3} \rceil = 2, ⌈115⌉=⌈2.2⌉=3\lceil \frac{11}{5} \rceil = \lceil 2.2 \rceil = 3 and ⌈74⌉=⌈1.75⌉=2\lceil \frac{7}{4} \rceil = \lceil 1.75 \rceil = 2.

Find the minimum possible number of ones in a good array.

给你两个整数 nn 和 kk。

一个长度为 nn 的数组 a1,a2,…,ana_1, a_2, \ldots, a_n(仅由 0 和 1 构成)被称为“好”的,当且仅当对所有从 11 到 nn 的整数 ii,以下两个条件均成立:

  • 数组 aa 的前 ii 个元素中,至少有 ⌈ik⌉\lceil \frac{i}{k} \rceil 个等于 11;
  • 数组 aa 的后 ii 个元素中,至少有 ⌈ik⌉\lceil \frac{i}{k} \rceil 个等于 11。

其中,⌈ik⌉\lceil \frac{i}{k} \rceil 表示将 ii 除以 kk 的结果向上取整。例如,⌈63⌉=2\lceil \frac{6}{3} \rceil = 2,⌈115⌉=⌈2.2⌉=3\lceil \frac{11}{5} \rceil = \lceil 2.2 \rceil = 3,⌈74⌉=⌈1.75⌉=2\lceil \frac{7}{4} \rceil = \lceil 1.75 \rceil = 2。

求一个“好”数组中 1 的最少可能个数。

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The only line of each test case contains two integers nn, kk (2≤n≤1002 \le n \le 100, 1≤k≤n1 \le k \le n) — the length of array and parameter kk from the statement.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

每个测试用例仅有一行,包含两个整数 nn、kk(2≤n≤1002 \le n \le 100,1≤k≤n1 \le k \le n)—— 分别为数组长度及题目描述中的参数 kk。

输出格式

For each test case output one integer — the minimum possible number of ones in a good array.

It can be shown that under the given constraints at least one good array always exists.

对于每个测试用例,输出一个整数——好数组中 1 的最小可能数量。

可以证明,在给定约束条件下,至少存在一个好数组。

输入输出样例

  • 输入#1

    7
    3 2
    5 2
    9 3
    7 1
    10 4
    9 5
    8 8

    输出#1

    2
    3
    4
    7
    4
    3
    2

说明/提示

In the first test case, n=3n = 3 and k=2k = 2:

  • Array [ 1,0,1 ][ \, 1, 0, 1 \, ] is good and the number of ones in it is 22.
  • Arrays [ 0,0,0 ][ \, 0, 0, 0 \, ], [ 0,1,0 ][ \, 0, 1, 0 \, ] and [ 0,0,1 ][ \, 0, 0, 1 \, ] are not good since for i=1i=1 the first condition from the statement is not satisfied.
  • Array [ 1,0,0 ][ \, 1, 0, 0 \, ] is not good since for i=1i=1 the second condition from the statement is not satisfied.
  • All other arrays of length 33 contain at least 22 ones.

Thus, the answer is 22.

In the second test case, n=5n = 5 and k=2k = 2:

  • Array [ 1,1,0,0,1 ][ \, 1, 1, 0, 0, 1 \, ] is not good since for i=3i=3 the second condition is not satisfied.
  • Array [ 1,0,1,0,1 ][ \, 1, 0, 1, 0, 1 \, ] is good and the number of ones in it is 33.
  • It can be shown that there is no good array with less than 33 ones, so the answer is 33.

In the third test case, n=9n = 9 and k=3k = 3:

  • Array [ 1,0,1,0,0,0,1,0,1 ][ \, 1, 0, 1, 0, 0, 0, 1, 0, 1 \, ] is good and the number of ones in it is 44.
  • It can be shown that there is no good array with less than 44 ones, so the answer is 44.

In the fourth test case, n=7n = 7 and k=1k = 1. The only good array is [ 1,1,1,1,1,1,1 ][ \, 1, 1, 1, 1, 1, 1, 1\, ], so the answer is 77.

在第一个测试用例中,n=3n = 3 且 k=2k = 2:

  • 数组 [ 1,0,1 ][ \, 1, 0, 1 \, ] 是合法的,其中 1 的个数为 22。
  • 数组 [ 0,0,0 ][ \, 0, 0, 0 \, ]、[ 0,1,0 ][ \, 0, 1, 0 \, ] 和 [ 0,0,1 ][ \, 0, 0, 1 \, ] 均不合法,因为当 i=1i=1 时,不满足题面中给出的第一条条件。
  • 数组 [ 1,0,0 ][ \, 1, 0, 0 \, ] 不合法,因为当 i=1i=1 时,不满足题面中给出的第二条条件。
  • 所有其余长度为 33 的数组均至少包含 22 个 1。

因此,答案为 22。

在第二个测试用例中,n=5n = 5 且 k=2k = 2:

  • 数组 [ 1,1,0,0,1 ][ \, 1, 1, 0, 0, 1 \, ] 不合法,因为当 i=3i=3 时,不满足第二条条件。
  • 数组 [ 1,0,1,0,1 ][ \, 1, 0, 1, 0, 1 \, ] 是合法的,其中 1 的个数为 33。
  • 可以证明,不存在 1 的个数少于 33 的合法数组,因此答案为 33。

在第三个测试用例中,n=9n = 9 且 k=3k = 3:

  • 数组 [ 1,0,1,0,0,0,1,0,1 ][ \, 1, 0, 1, 0, 0, 0, 1, 0, 1 \, ] 是合法的,其中 1 的个数为 44。
  • 可以证明,不存在 1 的个数少于 44 的合法数组,因此答案为 44。

在第四个测试用例中,n=7n = 7 且 k=1k = 1。唯一的合法数组是 [ 1,1,1,1,1,1,1 ][ \, 1, 1, 1, 1, 1, 1, 1\, ],因此答案为 77。

输入解题思路,AI测评打分。不知道怎么写?

首页