CF1929B.Sasha and the Drawing
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Even in kindergarten, Sasha liked a girl. Therefore, he wanted to give her a drawing and attract her attention.
As a drawing, he decided to draw a square grid of size n×n, in which some cells are colored. But coloring the cells is difficult, so he wants to color as few cells as possible. But at the same time, he wants at least k diagonals to have at least one colored cell. Note that the square grid of size n×n has a total of 4n−2 diagonals.
Help little Sasha to make the girl fall in love with him and tell him the minimum number of cells he needs to color.
即使在幼儿园时,萨沙就喜欢一个女孩。因此,他想送她一幅画来吸引她的注意。
作为这幅画,他决定画一个 n×n 的方格网格,其中部分格子被涂色。但涂色很费力,所以他希望涂色的格子数量尽可能少。与此同时,他又希望至少有 k 条对角线包含至少一个被涂色的格子。注意:一个 n×n 的方格网格总共有 4n−2 条对角线。
请帮小萨沙赢得女孩的芳心,并告诉他最少需要涂色多少个格子。
输入格式
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤1000) — the number of test cases. The description of the test cases follows.
The only line of each test case contains two integers n and k (2≤n≤108, 1≤k≤4n−2) — the size of the square grid and the minimum number of diagonals in which there should be at least one colored cell.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例仅有一行,包含两个整数 n 和 k(2≤n≤108,1≤k≤4n−2),分别表示正方形网格的大小以及要求至少有一个已着色格子的对角线的最小数量。
输出格式
For each test case, output a single integer — the minimum number of cells that need to be colored.
对于每个测试用例,输出一个整数——需要涂色的最少格子数。
输入输出样例
输入#1
7 3 4 3 3 3 10 3 9 4 7 7 11 2 3
输出#1
2 2 6 5 4 6 2
说明/提示
In the pictures below, the colored cells are marked in black, and all diagonals are marked in purple.
In the first test case, you can color 2 cells so that 4 diagonals contain at least one colored cell:

In the third test case, you can color 6 cells so that all 10 diagonals contain at least one colored cell:

在下面的图片中,彩色单元格以黑色标记,所有对角线均以紫色标记。
在第一个测试用例中,你可以给 2 个单元格染色,使得 4 条对角线上至少包含一个已染色的单元格:

在第三个测试用例中,你可以给 6 个单元格染色,使得全部 10 条对角线上都至少包含一个已染色的单元格:

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