Codeforces Round 926 (Div. 2) B. Sasha and the Drawing (Java)
比赛链接:Codeforces Round 926 (Div. 2)
B题传送门:B. Sasha and the Drawing
题目:B. Sasha and the Drawing

 Example
 input
3 4
3 3
3 10
3 9
4 7
7 11
2 3
output
2
6
5
4
6
2
分析:
由题可知,要我们计算着色最小单元格数量。
经过分析,我们可知:
在 1到 4(n-1) 个对角线,着色1个单元格,最多可以获得2个对角线。
在 4(n-1)+1 到 4n-2 个对角线,着色1个单元格,最多可以获得1个对角线。
例如:
 
 在 n=4 时,有6个单元格着色可以获得2个对角线,有2个单元格,着色可以获得1个对角线。
 
代码:
import java.util.*;
public class Main{
    public static void main(String[] args) {  
    	Scanner sc = new Scanner(System.in);
    	int tr = sc.nextInt();
    	while(tr-->0) {
    		int n = sc.nextInt();
    		int k = sc.nextInt();
    		// 计算获得2对彩色对角线的方块个数
    		int cnt2 = 2*(n-1);
    		int ans = 0;
    		if(k<=2*cnt2) {
    			ans = (k+1)/2;
    		}else {
    			ans = (k-cnt2);
    		}
    		
    		System.out.println(ans);
    	}
    	
    	sc.close();
    }
}



![在windows上安装好anaconda后,输入conda命令出现 OSError: [WinError 123] 文件名、目录名或卷标语法不正确。](https://img-blog.csdnimg.cn/direct/afedab6bc9a94838b18896d4e3a968ab.png)















