您的位置:首页 > 其它

QUT:E-Board

2015-11-26 11:30 155 查看

题目描述

There is a square of n*n.You need to cover the square with some small rectangle of k*1.How much can it cover at most?

输入

There are multiple test cases in the input file.

First line contain the number of cases T (T≤10000).

In the next T lines contain T cases , Each case has two integers n and k. (1≤n,k≤100)

输出

Print the maximum number of chessboard squares tiled.

样例输入

2 6 3 5 3


样例输出

3624

#include <cstdio>

using namespace std;

int main()
{
int T;
int n,k;

scanf("%d",&T);

for(int i=0;i<T;++i)
{
scanf("%d %d",&n,&k);
int x;
x=n%k;
if(k>n) printf("0\n");
else if(x<=k/2) printf("%d\n",n*n-x*x);
else printf("%d\n",n*n-(k-x)*(k-x));
}
}


当时就感觉这又会是一道找规律的题,然而找的规律并不完整,出现不符合原先推测的数据就不知道怎么办了,更改过多次,但还是没有做出来。

回来之后看了看讲解,我觉得这个画图真的是很重要,手动测数据的时候,画错一个就会浪费很多时间,思考方向也会有偏差。

首先判断k>n的情况,这种是填不上的;之后的规律我并没有想出来,当时我只想到n*n-x*x的这种情况,但显然测试是错误的,这种在测试n=7,k=4的时候出了错,应该是这样的,这个n*n的方格最后剩下的方格边长一定是小于k的,但按照我推出的规律,应该是剩下一个3*3的方格,但这样的话就会出现这种情况:

可以很容易的想到,在这个3*3方格旁边一定有一个被填充的1*4方格,这样我们就可以让它横着重新填充,这样就只剩一个了。

即(k-x),这种情况是在x<=k/2时才可能出现的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: